home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 2009-03-25 | 195.1 KB | 5,610 lines
var commentsbar_ff_tool = new Object(); commentsbar_ff_tool.Layout = 0; commentsbar_ff_tool.prevLayout = -1; commentsbar_ff_tool.guid = '{5A0035AB-8F83-4D03-BE4E-C8267A3A4A1A}'; commentsbar_ff_tool.ver = '1.0.1'; commentsbar_ff_tool.Var = new Array(); commentsbar_ff_tool.SVar = new Array(); commentsbar_ff_tool.userName = ''; commentsbar_ff_tool.userPasswd = ''; commentsbar_ff_tool.AffiliateID = ''; commentsbar_ff_tool.userid = ''; commentsbar_ff_tool.toolbarid = ''; commentsbar_ff_tool.explorer = null; commentsbar_ff_tool.promoCode = ""; commentsbar_ff_tool.firstlaunch = "1"; commentsbar_ff_tool.firstrun = "1"; commentsbar_ff_tool.ToolbarFace = ""; commentsbar_ff_tool.Font = ""; commentsbar_ff_tool.FontSize = ""; var commentsbar_ff_rotool = new Object(); commentsbar_ff_rotool.ver = commentsbar_ff_tool.ver; commentsbar_ff_rotool.guid = ''; //set in init commentsbar_ff_rotool.popupBlockedCnt = 0; //plugins// commentsbar_ff_rotool.autofill =0; var commentsbar_ff_hot_icons =0; var debugmode = 0; commentsbar_ff_tool.cookie = ''; commentsbar_ff_tool.document = document; commentsbar_ff_tool.window = window.self; commentsbar_ff_tool.url = ""; commentsbar_ff_tool.title = ""; var currentdomain = ''; var defenc = ''; function commentsbar_ff_redirect(url) {window._content.document.location=url;} commentsbar_ff_tool.redirect = commentsbar_ff_redirect; function cbLog(e) { Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService).logStringMessage(e); } function commentsbar_ff_limit_text(id, num) { try { if (num == '' || num == null || num == "undefined") return; var tb = document.getElementById(id); var n = num * 1; if (tb.value.length > n) tb.value = tb.value.substring(0, n); } catch(e) {/*alert(e)*/ } } commentsbar_ff_tool.getCustomXML = function(sName) { for (var j = 0; j < commentsbar_ff_customXml.length; j++) { if (commentsbar_ff_customXml[j].name == '_custom_xml_' + sName) return commentsbar_ff_customXml[j].xmldata; } return ''; } function commentsbar_ff_combochange() { try { var empty = true; var combos = document.getElementsByTagName("menulist"); var cmb_tmp; for (i = 0; i < combos.length; i++) { cmb_tmp = combos.item(i); if (cmb_tmp.value.length > 0) empty = false; } var tb = document.getElementById('commentsbar_ff-toolbar'); var cmd = tb.getElementsByTagName('command'); for (var j = 0; j < cmd.length; j++) { if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();') if (empty) cmd.item(j).setAttribute('disabled', 'true'); else cmd.item(j).setAttribute('disabled', 'false'); } } catch(e) {/*alert(e)*/ } } function commentsbar_ff_close_bubble() { if (bubblewindow != 0 && bubblewindow.closed == false) { bubblewindow.close(); return; } } commentsbar_ff_tool.closeBubble = commentsbar_ff_close_bubble; function commentsbar_ff_update_history() { commentsbar_ff_all_combo_update_history() } commentsbar_ff_tool.updateHistory = commentsbar_ff_update_history; function readcookies() { try { var cookieMgr = Components.classes["@mozilla.org/cookiemanager;1"] .getService(Components.interfaces.nsICookieManager); var e = cookieMgr.enumerator; var cookies = []; while (e.hasMoreElements()) { var cookie = e.getNext().QueryInterface(Components.interfaces.nsICookie); cookies.push(cookie); } commentsbar_ff_tool.cookie = ''; for (var i = 0; i < cookies.length; ++i) { var temp = cookies[i].host.substring(1, cookies[i].host.length); if (currentdomain.indexOf(temp) != -1) { if (commentsbar_ff_tool.cookie != '') commentsbar_ff_tool.cookie += ';'; commentsbar_ff_tool.cookie += cookies[i].name + '=' + cookies[i].value; } } } catch(e) { if (debugmode) cbLog(e); } } var primaryurl = ''; //setTimeout('commentsbar_ff_timer();', 60000); var commentsbar_ff_time = 0; function commentsbar_ff_plugin_init() { if (commentsbar_ff_rotool.autofill == 1) { commentsbar_ff_autofill_init(); } } function commentsbar_ff_GetVariable(name) { try { var tmp; name = name.replace(/[\#\\.]/g, ''); var saved_param = commentsbar_ff_load_pref("commentsbar_ff_tool.variable" + name, ""); if (saved_param) tmp = saved_param; else eval('tmp=commentsbar_ff_tool.variable' + name + ';'); if (!tmp) tmp = ''; return tmp; } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_SetVariable(name, val) { try { name = name.replace(/[\#\\.]/g, ''); eval('commentsbar_ff_tool.variable' + name + '=\'' + val + '\';'); commentsbar_ff_pref("commentsbar_ff_tool.variable" + name, val.toString()); } catch(e) { if (debugmode) cbLog(e); } } commentsbar_ff_tool.GetVariable = commentsbar_ff_GetVariable; commentsbar_ff_tool.SetVariable = commentsbar_ff_SetVariable; function commentsbar_ff_GetContent() { try { return window._content.document.getElementsByTagName("BODY")[0].innerHTML; } catch(e) { if (debugmode) cbLog(e); } } commentsbar_ff_tool.GetContent = commentsbar_ff_GetContent; function commentsbar_ff_GetById(id) { try { return window._content.document.getElementById(id); } catch(e) { if (debugmode) cbLog(e); } } commentsbar_ff_tool.getElementById = commentsbar_ff_GetById; commentsbar_ff_tool.getElementByID = commentsbar_ff_GetById; function commentsbar_ff_GetByTagName(id) { try { return window._content.document.getElementsByTagName(id); } catch(e) { if (debugmode) cbLog(e); } } commentsbar_ff_tool.getElementsByTagName = commentsbar_ff_GetByTagName; function commentsbar_ff_external_search(href) { try { var set_ext_search = document.getElementById('settings_external_search'); if (!set_ext_search) return; var engines = set_ext_search.getAttribute('value'); if (!engines) return; var mas_eng = engines.split('/***/'); for (var i = 0; i < mas_eng.length; i++) { if (!mas_eng[i]) return; var cur_engine = mas_eng[i].split(';'); //target;engine;param var re = cur_engine[1]; re = re.replace(/\./g, '\.'); re = re.replace(/\*/g, '.*'); re = re.replace(/\?/g, '.?'); var reg_exp = new RegExp(re); if (href.match(reg_exp)) { reg_exp = new RegExp('.*' + cur_engine[2] + '([^\&]*).*'); if (href.match(reg_exp)) { var text = href.replace(reg_exp, "$1"); var combo = document.getElementById(cur_engine[0]); if (combo) { try { var characterSet = window._content.document.characterSet; const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"] .getService(Components.interfaces.nsITextToSubURI); text = textToSubURI.unEscapeURIForUI(characterSet, text); } catch(ex) { } combo.value = text; //.replace(/\+/g,' '); } } } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_settings_allowpopups(remove) { try { var set_allowpopups = document.getElementById('settings_allowpopups'); if (set_allowpopups) { var ap = set_allowpopups.getAttribute('value'); if (ap) { var ap_sites = ap.split(';'); var ci; for (ci = 0; ci < ap_sites.length; ci++) if (ap_sites[ci]) { var service = Components.classes['@mozilla.org/permissionmanager;1'].getService(Components.interfaces.nsIPermissionManager); var url = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURL); url.spec = ap_sites[ci]; var isAllowed = service.testPermission(url, "popup"); if (isAllowed && remove == true) { host = url.spec; host = host.replace(/\/$/, ''); service.remove(host, "popup"); } else if (!isAllowed) { service.add(url, "popup", 1); } } } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_timer() { try { var tb = document.getElementById('commentsbar_ff-toolbar'); if (!tb) return; commentsbar_ff_time++; //manage include xml var tb = document.getElementById('commentsbar_ff-toolbar'); var inc = tb.getElementsByTagName("box"); var i; if (requests) { var cmb_tmp; refresh_queue = new Array(); for (i = 0; i < inc.length; i++) { cmb_tmp = inc.item(i); if (!cmb_tmp.getAttribute('filename') || !cmb_tmp.getAttribute('expire')) continue; if (commentsbar_ff_time % cmb_tmp.getAttribute('expire') == 0) refresh_queue.push(cmb_tmp.getAttribute('id')); } commentsbar_ff_expire_refresh_include_xml(); } //manage banner var ban = tb.getElementsByTagName('iframe'); if (ban) { for (i = 0; i < ban.length; i++) { if (!ban[i].getAttribute('expire')) continue; if (commentsbar_ff_time % ban[i].getAttribute('expire') == 0) { if (ban[i].getAttribute('bannertype') != 'script' && ban[i].webNavigation) //ban[i].webNavigation.reload(Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH); ban[i].webNavigation.loadURI(commentsbar_ff_macro_substitution_utf8(ban[i].getAttribute('url')), Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null); } } } setTimeout('commentsbar_ff_timer();', 60000); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_check_banner(e) { try { var title = e.originalTarget.title; var loc = e.originalTarget.location; var tb = document.getElementById('commentsbar_ff-toolbar'); var banners = tb.getElementsByTagName('iframe'); for (var i = 0; i < banners.length; i++) if (banners.item(i).getAttribute('src') == loc) break; if (i == banners.length) return; var banner = banners.item(i); if (title == '404 Not Found') { if (banner.getAttribute('bannertype') != 'script' && banner.getAttribute('local')) { banner.removeEventListener("load", commentsbar_ff_check_banner, true); banner.setAttribute('src', 'chrome://commentsbar_ff/content/' + banner.getAttribute('local')); banner.webNavigation.loadURI('chrome://commentsbar_ff/content/' + banner.getAttribute('local'), Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null); banner.addEventListener("load", commentsbar_ff_check_banner, true); } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_refresh_banner(sync) { try { var tb = document.getElementById('commentsbar_ff-toolbar'); if (!tb || !window.toolbar.visible) return; var ban = tb.getElementsByTagName('iframe'); if (ban) { for (var i = 0; i < ban.length; i++) { //if (!ban[i].getAttribute('sync')) continue; if (ban[i].getAttribute('sync') == sync || ban[i].getAttribute('sync') == "both")// || (!ban[i].getAttribute('sync') && sync=='OnDocumentComplete')) { if (ban[i].getAttribute('bannertype') != 'script' && ban[i].webNavigation) { if (ban[i].getAttribute('url')) ban[i].setAttribute('src', commentsbar_ff_macro_substitution_utf8(ban[i].getAttribute('url'))); //ban[i].webNavigation.reload(Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH); if (ban[i].getAttribute('src') && ban[i].getAttribute('src') != '') ban[i].webNavigation.loadURI(commentsbar_ff_macro_substitution_utf8(ban[i].getAttribute('src')), Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null); } } } } init_script_commentsbar_ff(sync); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_set_hot(id) { try { if (id == '') return; var b = document.getElementById(id); if (!b) return; var tagimage; var f = 0; //0-attr; 1-tag var img; img = b.getAttribute('image'); if (!img) { tagimage = document.getElementById(id + '_img'); if (!tagimage) return; img = tagimage.getAttribute('src'); if (!img) return; f = 1; } if (!b.getAttribute('hot_image')) //icons { if (!commentsbar_ff_hot_icons) return; img = img.replace(/img/, 'himg'); if (f) tagimage.setAttribute('src', img); else b.setAttribute('image', img); } else { var himg = b.getAttribute('hot_image'); if (!himg) return; if (f) tagimage.setAttribute('src', himg); else b.setAttribute('image', himg); b.setAttribute('hot_image', img); } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_set_nothot(id) { try { if (id == '') return; var b = document.getElementById(id); if (!b) return; var tagimage; var f = 0; //0-attr; 1-tag var img; img = b.getAttribute('image'); if (!img) { tagimage = document.getElementById(id + '_img'); if (!tagimage) return; img = tagimage.getAttribute('src'); if (!img) return; f = 1; } if (!b.getAttribute('hot_image')) //icons { if (!commentsbar_ff_hot_icons) return; img = img.replace(/himg/, 'img'); if (f) tagimage.setAttribute('src', img); else b.setAttribute('image', img); } else { var himg = b.getAttribute('hot_image'); if (!himg) return; if (f) tagimage.setAttribute('src', himg); else b.setAttribute('image', himg); b.setAttribute('hot_image', img); } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_gen_toolbar_id() { if (commentsbar_ff_getPref("commentsbar_ff.guid") == null) { var S = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); var id = '{'; for (i = 0; i < 8; i++) id = id + S[Math.round(Math.random() * 15)]; id = id + '-'; for (i = 0; i < 4; i++) id = id + S[Math.round(Math.random() * 15)]; id = id + '-'; for (i = 0; i < 4; i++) id = id + S[Math.round(Math.random() * 15)]; id = id + '-'; for (i = 0; i < 4; i++) id = id + S[Math.round(Math.random() * 15)]; id = id + '-'; for (i = 0; i < 12; i++) id = id + S[Math.round(Math.random() * 15)]; id = id + '}'; //commentsbar_ff_set_opt ('guid', id); commentsbar_ff_pref("commentsbar_ff.guid", id); } //return commentsbar_ff_get_opt('guid'); return commentsbar_ff_getPref("commentsbar_ff.guid"); } function commentsbar_ff_uninstall() { //This function is never called - to be cleaned up later return; try { var name = "toolbar"; var tb = document.getElementById('commentsbar_ff-toolbar'); if (tb && tb.toolbarName) name = tb.toolbarName; var text = "This will remove the " + name + " from your computer. Are you sure?"; var msg = document.getElementById("message_uninstallMsg"); if (msg) text = msg.getAttribute('value'); if (!window.confirm(text)) return; commentsbar_ff_pref('general.useragent.override', navigator.userAgent); commentsbar_ff_clearPref('general.useragent.override'); if (navigator.userAgent.indexOf('Firefox') != -1 || navigator.userAgent.indexOf('BonEcho') != -1 || navigator.userAgent.indexOf('Minefield') != -1 || navigator.userAgent.indexOf('Netscape/8') != -1) { var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"] .getService(Components.interfaces.nsIExtensionManager); var rds = gExtensionManager.datasource; if (gExtensionManager.uninstallItem) gExtensionManager.uninstallItem(commentsbar_ff_tool.guid); if (gExtensionManager.uninstallExtension) gExtensionManager.uninstallExtension(commentsbar_ff_tool.guid); for (var j = 0; j < commentsbar_ff_customXml.length; j++) commentsbar_ff_pref("commentsbar_ff.custom_xmls." + commentsbar_ff_customXml[j].name,""); commentsbar_ff_pref("commentsbar_ff.custom_xmls", ""); commentsbar_ff_customXml = new Array(); for (i = 1; i <= 10; i++) { eval('commentsbar_ff_pref( "commentsbar_ff.Var' + i + '", "0")'); eval('commentsbar_ff_pref( "commentsbar_ff.SVar' + i + '", "0")'); } commentsbar_ff_settings_allowpopups(true); commentsbar_ff_clearhistory(""); commentsbar_ff_tool.firstlaunch = "1"; var uninstallURL = document.getElementById('url_urlAfterUninstall'); if (uninstallURL.getAttribute('value')) commentsbar_ff_webjump(uninstallURL.getAttribute('value'), "", "", ""); alert('Restart the browser.'); } else { var uninstallURL = document.getElementById('url_urlAfterUninstall'); if (uninstallURL.getAttribute('value')) commentsbar_ff_webjump(uninstallURL.getAttribute('value'), "", "", ""); commentsbar_ff_clearhistory(""); commentsbar_ff_tool.firstlaunch = "1"; try { jslibUninstall('untitled'); } catch(k) { var str = "urn:mozilla:package:commentsbar_ff"; oExtUninstall = new ExtensionUninstall(str); success = oExtUninstall.uninstall(); } alert('Restart the browser.'); } } catch(e) { if (debugmode) cbLog(e); } } var commentsbar_ff_wnd; function commentsbar_ff_update() { //AMO doesn't allow this,return to Firefox default - automatically check as per a ff pref return; try { if (navigator.userAgent.indexOf('Firefox') != -1 || navigator.userAgent.indexOf('BonEcho') != -1 || navigator.userAgent.indexOf('Minefield') != -1) { var id = commentsbar_ff_tool.guid; var itemType = Components.interfaces.nsIUpdateItem.TYPE_EXTENSION; var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"] .getService(Components.interfaces.nsIExtensionManager); var items; try { items = gExtensionManager.getItemList(id, itemType, { }); var updates = Components.classes["@mozilla.org/updates/update-service;1"] .getService(Components.interfaces.nsIUpdateService); updates.checkForUpdates(items, items.length, itemType, Components.interfaces.nsIUpdateService.SOURCE_EVENT_USER, window); } catch(e) { BrowserOpenExtensions('extensions'); items = [gExtensionManager.getItemForID(id)]; gExtensionManager.update(items, items.length, false, null); } } } catch(e) { try { const EMTYPE = "Extension:Manager"; var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator); var theEM = wm.getMostRecentWindow(EMTYPE); if (theEM) { theEM.focus(); return; } const EMURL = "chrome://mozapps/content/extensions/extensions.xul"; const EMFEATURES = "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable"; commentsbar_ff_wnd = 0; commentsbar_ff_wnd = window.openDialog(EMURL, "", EMFEATURES); setTimeout('postupdate();', 250); return; } catch(e) { } } } function postupdate() { try { if (commentsbar_ff_wnd == 0) { setTimeout('postupdate();', 250); return; } var item = commentsbar_ff_wnd.document.getElementById('checkUpdatesAllButton'); item.doCommand(); } catch(e) { } } // HIGHLIGHT var commentsbar_ff_highlight_colours = new Array(); commentsbar_ff_highlight_colours.push('rgb(246, 255, 0)'); commentsbar_ff_highlight_colours.push('rgb(0, 255, 228)'); commentsbar_ff_highlight_colours.push('rgb(90, 255, 0)'); commentsbar_ff_highlight_colours.push('rgb(0, 135, 255)'); commentsbar_ff_highlight_colours.push('rgb(255, 204, 0)'); commentsbar_ff_highlight_colours.push('rgb(255, 0, 240)'); function commentsbar_ff_load_highlight_colors() { try { var set = document.getElementById('settings_highlight'); if (!set) return; var c = set.getAttribute('colors'); var colors = c.split(';'); colors.pop(); commentsbar_ff_highlight_colours = new Array(); for (i = 0; i < colors.length; i++) commentsbar_ff_highlight_colours[i] = colors[i]; } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_rgb_to_hex(rgb) { var c = "#"; try { if (rgb == '') return c; rgb = rgb.split(','); if (rgb.length < 3) return c; c += commentsbar_ff_toHex(rgb[0]); c += commentsbar_ff_toHex(rgb[1]); c += commentsbar_ff_toHex(rgb[2]); } catch(e) { if (debugmode) cbLog(e); } return c; } function commentsbar_ff_menu_active(e) { try { if ((e.type == "mouseover" || e.type == "focus")) { if (e.target.hasAttribute('menu_style_over')) e.target.setAttribute('style', e.target.getAttribute('menu_style_over')); } else { if (e.target.hasAttribute('menu_style_out')) e.target.setAttribute('style', e.target.getAttribute('menu_style_out')); } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_color_schema() { try { var tb = document.getElementById('commentsbar_ff-toolbar'); tb.setAttribute('style', "max-height:20pt"); var schm = document.getElementById('color_schema'); if (!schm || !tb) return; //load toolbar styles var bBackground = false; var tb_skin = schm.getAttribute('toolbar_skin'); if (tb_skin != '' && tb.parentNode && tb.parentNode.style) { var parStyle = tb.parentNode.getAttribute('style'); parStyle += 'background-image:url("' + tb_skin + '");'; tb.parentNode.setAttribute('style', parStyle); bBackground = true; } var style = tb.getAttribute('style'); var tbf = commentsbar_ff_rgb_to_hex(schm.getAttribute('toolbar_face')); if (!bBackground && tbf != '#') style += "background-color:" + tbf + ";"; tb.setAttribute('style', style); //load menus styles var menu_item = commentsbar_ff_rgb_to_hex(schm.getAttribute('menu')); var menu_sel = commentsbar_ff_rgb_to_hex(schm.getAttribute('selected_menu_item')); var menu_text = commentsbar_ff_rgb_to_hex(schm.getAttribute('text')); var menu_sel_text = commentsbar_ff_rgb_to_hex(schm.getAttribute('highlight_text')); var menus = tb.getElementsByTagName("menuitem"); for (var i = 0; i < menus.length; i++) commentsbar_ff_apply_menu_style(menus[i], menu_item, menu_text, menu_sel, menu_sel_text); menus = tb.getElementsByTagName("menu"); for (var i = 0; i < menus.length; i++) commentsbar_ff_apply_menu_style(menus[i], menu_item, menu_text, menu_sel, menu_sel_text); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_apply_menu_style(menu, menu_item, menu_text, menu_sel, menu_sel_text) { try { var menu_style_out = menu.getAttribute('style'); if (menu_text != '#') menu_style_out += "color:" + menu_text + ";"; var menu_style_over = menu_style_out; if (menu_item != '#') menu_style_out += "background-color:" + menu_item + ";"; if (menu_sel != '#') menu_style_over += "background-color:" + menu_sel + ";"; if (menu_sel_text != '#') menu_style_over += "color:" + menu_sel_text + ";"; menu.setAttribute('menu_style_out', menu_style_out); menu.setAttribute('menu_style_over', menu_style_over); menu.setAttribute('style', menu_style_out); menu.addEventListener('mouseover', commentsbar_ff_menu_active, true); menu.addEventListener('mouseout', commentsbar_ff_menu_active, true); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_get_input_terms() { var i, j, k, quot, t, terms = new Array(); var tb = document.getElementById('commentsbar_ff-toolbar'); var combos = tb.getElementsByTagName("menulist"); for (var i = 0; i < combos.length; i++) { var quot1 = combos[i].value; if (!quot1 || quot1 == 'undefined') continue; if (quot1 == combos[i].getAttribute("text") || quot1 == combos[i].getAttribute("ptext")) continue; quot = quot1.split('"'); for (var j = 0; j < quot.length; j++) { if (j % 2) { if (quot[j] != '') terms.push(quot[j]); } else { t = quot[j].split(' '); for (var k = 0; k < t.length; k++) { if (t[k] != '') terms.push(t[k]); } } } } var combos = tb.getElementsByTagName("textbox"); for (var i = 0; i < combos.length; i++) { var quot1 = combos[i].value; if (!quot1 || quot1 == 'undefined') continue; if (quot1 == combos[i].getAttribute("text") || quot1 == combos[i].getAttribute("ptext")) continue; quot = quot1.split('"'); for (var j = 0; j < quot.length; j++) { if (j % 2) { if (quot[j] != '') terms.push(quot[j]); } else { t = quot[j].split(' '); for (var k = 0; k < t.length; k++) { if (t[k] != '') terms.push(t[k]); } } } } return terms; } function highlightRange(range, color, id) { var startContainer = range.startContainer; var spanNode = startContainer.ownerDocument.createElement("layer"); if (color.length < 7) color = '#' + color; spanNode.style.backgroundColor = color; spanNode.style.color = "black"; spanNode.id = id; var docfrag = range.extractContents(); spanNode.appendChild(docfrag); range.insertNode(spanNode); return spanNode } function isWordCharacter(ch) { if (ch == null || typeof ch != "string" || ch.length != 1) { return false } var code = ch.charCodeAt(0); return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 138 && code <= 142 || code >= 154 && code <= 159 || code >= 192 && code <= 255 } function isNodeInputNodeOrChildOf(node) { if (node.nodeName.toUpperCase() == "INPUT") { return true } if (node.parentNode != null) { return isNodeInputNodeOrChildOf(node.parentNode) } return false } function commentsbar_ff_Highlight_aux(win, word, colour) { try { var set1, f; for (f = 0; f < win.frames.length; f++) { commentsbar_ff_Highlight_aux(win.frames[f], word, colour); } var doc = win.document; if (doc != null) { var body = doc.body; if (body != null) { var docRange = doc.createRange(); docRange.selectNode(body); var startRange = docRange.cloneRange(); startRange.collapse(true); var stopRange = docRange.cloneRange(); stopRange.collapse(false); var findRange = Components.classes["@mozilla.org/embedcomp/rangefind;1"].createInstance(); if (findRange != null && findRange instanceof Components.interfaces.nsIFind) { findRange.caseSensitive = false; findRange.findBackwards = false; var result = findRange.Find(word, docRange, startRange, stopRange); while (null != result) { if (result.endContainer != null && result.startContainer != null && result.endContainer.nodeType == Node.TEXT_NODE && result.startContainer.nodeType == Node.TEXT_NODE && ! isNodeInputNodeOrChildOf(result.startContainer) && ! isNodeInputNodeOrChildOf(result.endContainer)) { var startChar = null; if (result.startOffset > 0) { startChar = result.startContainer.nodeValue.charAt(result.startOffset - 1) } var endChar = result.endContainer.nodeValue.charAt(result.endOffset); if (1)// ! isWordCharacter(startChar) && ! isWordCharacter(endChar)) { var spanNode = highlightRange(result, colour, "toolbar-highlight"); startRange.selectNode(spanNode); } else { startRange = result } } else { startRange = result } startRange.collapse(false); result = findRange.Find(word, docRange, startRange, stopRange) } } } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_Highlight_aux_undo(win) { var result = false; if (win != null) { var doc = win.document; if (win.frames != null) { for (var i = 0; i < win.frames.length; i ++) { if (commentsbar_ff_Highlight_aux_undo(win.frames[i])) { result = true } } } if (! result) { var layer = doc.getElementById("toolbar-highlight"); while (layer != null) { var parent = layer.parentNode; var children = layer.childNodes; for (var index = children.length - 1; index >= 0; index --) { parent.insertBefore(children[0], layer) } parent.removeChild(layer); result = true; layer = doc.getElementById("toolbar-highlight") } } } return result } //function commentsbar_ff_Highlight_aux (win, word, colour) //{ // var set1, f; // for (f = 0; f < win.frames.length; f++) { // commentsbar_ff_Highlight_aux (win.frames[f], word, colour); /* set1 = win.frames[f].document.body.innerHTML.split('<'); for (i in set1) { set2 = set1[i].split('>'); if (set2.length > 1) { eval("set2[1] = set2[1].replace('"+word+"', '<layer id=\"toolbar-highlight\" style=\"background-color:#' + colour + ';color: rgb(0,0,0);\">"+word+"</layer>')"); var str=word[0].toUpperCase(); word2=word.substring(1,word.length); word2=str+word2; eval("set2[1] = set2[1].replace('"+word2+"', '<layer id=\"toolbar-highlight\" style=\"background-color:#' + colour + ';color: rgb(0,0,0);\">"+word2+"</layer>')"); } set1[i] = set2.join('>'); } win.frames[f].document.body.innerHTML = set1.join('<'); } } */ var prev_commentsbar_ff_Highlight = new Array(); function commentsbar_ff_Highlight() { try { var i, changed = 1; var colours = commentsbar_ff_highlight_colours; var terms = commentsbar_ff_get_input_terms(), prev = prev_commentsbar_ff_Highlight; if (terms.length == prev.length) { changed = 0; for (var i = 0; i < terms.length; i++) { if (terms[i] != prev[i]) changed = 1; } } if (!changed) { for (var i = 0; i < prev.length; i++) { // commentsbar_ff_Highlight_aux_undo (window.self, prev[i], colours[i % colours.length]); var tb = document.getElementById('commentsbar_ff-toolbar'); var cmd = tb.getElementsByTagName('command'); for (var j = 0; j < cmd.length; j++) { if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();') cmd.item(j).setAttribute('checked', 'false'); } var tabBrowser = document.getElementById("content"); commentsbar_ff_Highlight_aux_undo(tabBrowser.selectedBrowser.contentWindow); } prev_commentsbar_ff_Highlight = new Array(); } else { var tb = document.getElementById('commentsbar_ff-toolbar'); var cmd = tb.getElementsByTagName('command'); for (var j = 0; j < cmd.length; j++) { if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();') cmd.item(j).setAttribute('checked', 'true'); } for (var i = 0; i < prev.length; i++) { // commentsbar_ff_Highlight_aux_undo (window.self, prev[i], colours[i % colours.length]); var tabBrowser = document.getElementById("content"); commentsbar_ff_Highlight_aux_undo(tabBrowser.selectedBrowser.contentWindow); } for (var i = 0; i < terms.length; i++) { // commentsbar_ff_Highlight_aux (window.self, terms[i], colours[i % colours.length]); var tabBrowser = document.getElementById("content"); commentsbar_ff_Highlight_aux(tabBrowser.selectedBrowser.contentWindow, terms[i], colours[i % colours.length]); } prev_commentsbar_ff_Highlight = terms; } } catch(e) { if (debugmode) cbLog(e); } } //////////// function commentsbar_ff_allowPopups() { try { var service = Components.classes['@mozilla.org/permissionmanager;1'].getService(Components.interfaces.nsIPermissionManager); var url = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURL); if (window._content.document.location.href == 'about:blank') return; url.spec = window._content.document.location.host; var isAllowed = service.testPermission(url, "popup"); if (isAllowed) { host = url.spec; host = host.replace(/\/$/, ''); service.remove(host, "popup"); } else { service.add(url, "popup", 1); } commentsbar_ff_allowPopupsCheck(); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_allowPopupsCheck() { try { var service = Components.classes['@mozilla.org/permissionmanager;1'].getService(Components.interfaces.nsIPermissionManager); var url = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURL); if (window._content.document.location.href == 'about:blank') return; url.spec = window._content.document.location.host; var isAllowed = service.testPermission(url, "popup"); var tags = new Array('toolbarbutton'); for (var k = 0; k < tags.length; k++) { var tb = document.getElementById('commentsbar_ff-toolbar'); var buttons = tb.getElementsByTagName(tags[k]); var b_tmp, c_tmp, cmd, oncmd; for (i = 0; i < buttons.length; i++) { b_tmp = buttons.item(i); c_tmp = b_tmp.getAttribute('command'); if (c_tmp && c_tmp != 'undefined' && c_tmp != null && c_tmp != "cmd_") { cmd = document.getElementById(c_tmp); if (!cmd) continue; oncmd = cmd.getAttribute('oncommand'); if (oncmd == 'commentsbar_ff_allowPopups();') { if (isAllowed == 1) b_tmp.setAttribute('checked', "true"); else b_tmp.setAttribute('checked', "false"); if (isAllowed) { if (b_tmp.getAttribute('plabel')) { var l = b_tmp.getAttribute('plabel'); l = l.replace("#cnt#", commentsbar_ff_rotool.popupBlockedCnt); b_tmp.setAttribute('label', l); } if (b_tmp.getAttribute('rimage')) { b_tmp.setAttribute('oimage', b_tmp.getAttribute('image')); b_tmp.setAttribute('image', b_tmp.getAttribute('rimage')); } } else { commentsbar_ff_rotool.popupBlockedCnt = commentsbar_ff_load_pref("commentsbar_ff.popupblockedcnt", "0"); var l = b_tmp.getAttribute('rlabel'); l = l.replace("#cnt#", commentsbar_ff_rotool.popupBlockedCnt); b_tmp.setAttribute('label', l); if (b_tmp.getAttribute('oimage')) b_tmp.setAttribute('image', b_tmp.getAttribute('oimage')); } } } } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_allowPopupsCount() { try { if (window._content.document.location.href == 'about:blank') return; var tags = new Array('toolbarbutton'); for (var k = 0; k < tags.length; k++) { var tb = document.getElementById('commentsbar_ff-toolbar'); var buttons = tb.getElementsByTagName(tags[k]); var b_tmp, c_tmp, cmd, oncmd; for (var i = 0; i < buttons.length; i++) { b_tmp = buttons.item(i); c_tmp = b_tmp.getAttribute('command'); if (c_tmp && c_tmp != 'undefined' && c_tmp != null) { cmd = document.getElementById(c_tmp); if (!cmd) continue; oncmd = cmd.getAttribute('oncommand'); if (oncmd == 'commentsbar_ff_allowPopups();') commentsbar_ff_clearcount(); } } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_blockPopups() { try { var pref = 'dom.disable_open_during_load'; var p = navigator.preference(pref); navigator.preference(pref, !p); var tags = new Array('toolbarbutton', 'menuitem'); for (var k = 0; k < tags.length; k++) { var tb = document.getElementById('commentsbar_ff-toolbar'); var buttons = tb.getElementsByTagName(tags[k]); var b_tmp, c_tmp, cmd, oncmd; for (i = 0; i < buttons.length; i++) { b_tmp = buttons.item(i); c_tmp = b_tmp.getAttribute('command'); if (c_tmp && c_tmp != 'undefined' && c_tmp != null) { cmd = document.getElementById(c_tmp); if (!cmd) continue; oncmd = cmd.getAttribute('oncommand'); if (oncmd == 'commentsbar_ff_blockPopups();') b_tmp.setAttribute('checked', !p); if (!p) { if (b_tmp.getAttribute('plabel')) { var l = b_tmp.getAttribute('plabel'); //b_tmp.setAttribute('olabel', b_tmp.getAttribute('label')); b_tmp.setAttribute('label', l.replace(/#cnt#/, commentsbar_ff_rotool.popupBlockedCnt)); } if (b_tmp.getAttribute('rimage')) { b_tmp.setAttribute('oimage', b_tmp.getAttribute('image')); b_tmp.setAttribute('image', b_tmp.getAttribute('rimage')); } } else { commentsbar_ff_rotool.popupBlockedCnt = commentsbar_ff_load_pref("commentsbar_ff.popupblockedcnt", "0"); //if (b_tmp.getAttribute('olabel')) b_tmp.setAttribute('label', b_tmp.getAttribute('rlabel')); if (b_tmp.getAttribute('oimage')) b_tmp.setAttribute('image', b_tmp.getAttribute('oimage')); } } } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_blockPopupsInit() { try { var pref = 'dom.disable_open_during_load'; var p = navigator.preference(pref); var tags = new Array('toolbarbutton', 'menuitem'); for (var k = 0; k < tags.length; k++) { var tb = document.getElementById('commentsbar_ff-toolbar'); var buttons = tb.getElementsByTagName(tags[k]); for (i = 0; i < buttons.length; i++) { var b_tmp = buttons.item(i); if (p) { if (b_tmp.getAttribute('plabel')) { var l = b_tmp.getAttribute('plabel'); b_tmp.setAttribute('label', l.replace(/#cnt#/, commentsbar_ff_rotool.popupBlockedCnt)); } if (b_tmp.getAttribute('rimage')) { b_tmp.setAttribute('oimage', b_tmp.getAttribute('image')); b_tmp.setAttribute('image', b_tmp.getAttribute('rimage')); } var c_tmp = b_tmp.getAttribute('command'); if (c_tmp && c_tmp != 'undefined' && c_tmp != null) { var cmd = document.getElementById(c_tmp); if (!cmd) continue; var oncmd = cmd.getAttribute('oncommand'); if (oncmd == 'commentsbar_ff_blockPopups();') b_tmp.setAttribute('checked', p); } } else { commentsbar_ff_rotool.popupBlockedCnt = commentsbar_ff_load_pref("commentsbar_ff.popupblockedcnt", "0"); b_tmp.setAttribute('label', b_tmp.getAttribute('rlabel')); if (b_tmp.getAttribute('oimage')) b_tmp.setAttribute('image', b_tmp.getAttribute('oimage')); } } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_clearcount() { commentsbar_ff_rotool.popupBlockedCnt = 0; commentsbar_ff_pref("commentsbar_ff.popupblockedcnt", commentsbar_ff_rotool.popupBlockedCnt.toString()); commentsbar_ff_update_popup_cnt(); } function commentsbar_ff_clearclipboard(message) { try { if (!message || message == '' || confirm(message)) { cb = Components.classes["@mozilla.org/widget/clipboard;1"] .getService(Components.interfaces.nsIClipboard); cb.emptyClipboard(Components.interfaces.nsIClipboard.kGlobalClipboard); } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_clearurlbarhistory(message) { try { /* if (!message || message == '' || confirm(message)) { var urlbarhist = Components.classes["@mozilla.org/browser/urlbarhistory;1"] .getService(Components.interfaces.nsIUrlbarHistory); urlbarhist.clearHistory(); } */ } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_clearcookie(message) { if (!message || message == '' || confirm(message)) { var cookiemanager = Components.classes["@mozilla.org/cookiemanager;1"] .getService(Components.interfaces.nsICookieManager); cookiemanager.removeAll(); } } function commentsbar_ff_clearcache(message) { if (!message || message == '' || confirm(message)) { var cacheService = Components.classes["@mozilla.org/network/cache-service;1"] .getService(Components.interfaces.nsICacheService); cacheService.evictEntries(Components.interfaces.nsICache.STORE_ANYWHERE); } } function commentsbar_ff_cleariehistory(message) { if (!message || message == '' || confirm(message)) { var globalHistory = Components.classes['@mozilla.org/browser/global-history;2'] .getService(Components.interfaces.nsIBrowserHistory); globalHistory.removeAllPages(); } } function commentsbar_ff_clearautofill(message) { if (!message || message == '' || confirm(message)) { var formHistory = Components.classes["@mozilla.org/satchel/form-history;1"] .getService(Components.interfaces.nsIFormHistory); formHistory.removeAllEntries(); } } //COMBO //update from onLocationChange function commentsbar_ff_clearhistory(message) { if (!(!message || message == '' || confirm(message))) return; var combos = document.getElementsByTagName("menulist"); var cmb_tmp; for (i = 0; i < combos.length; i++) { cmb_tmp = combos.item(i); if (cmb_tmp.getAttribute('editable') == 'true') { cmb_tmp.removeAllItems(); commentsbar_ff_pref("commentsbar_ff.stored_history" + cmb_tmp.getAttribute('id'), ''); } cmb_tmp.value = ''; } } function commentsbar_ff_combo_clear() { try { var tb = document.getElementById('commentsbar_ff-toolbar'); var combos = tb.getElementsByTagName("menulist"); var cmb_tmp; for (i = 0; i < combos.length; i++) { cmb_tmp = combos.item(i); var menu = cmb_tmp.childNodes.item(0); if (cmb_tmp.getAttribute('id') && cmb_tmp.getAttribute('editable') == 'true') cmb_tmp.value = ""; } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_all_combo_update_history() { try { var settings_box = document.getElementById('settings'); if (settings_box.getAttribute('keephistory') == '0') return; var tb = document.getElementById('commentsbar_ff-toolbar'); var combos = tb.getElementsByTagName("menulist"); var cmb_tmp, hist, histor, itm; for (i = 0; i < combos.length; i++) { cmb_tmp = combos.item(i); var menu = cmb_tmp.childNodes.item(0); if (cmb_tmp.getAttribute('id') && cmb_tmp.getAttribute('editable') == 'true' && ((!menu) || (menu && !menu.childNodes.item(0)))) { histor = commentsbar_ff_load_pref("commentsbar_ff.stored_history" + cmb_tmp.getAttribute('id'), ""); if (histor == '' || histor == 'undefined') { if (cmb_tmp.value && cmb_tmp.value != '') commentsbar_ff_combo_update_history(cmb_tmp.getAttribute('id')); continue; } /* if (histor == '' || histor == 'undefined') { if (cmb_tmp.value && cmb_tmp.value != '') histor=cmb_tmp.value; else continue; } */ hist = histor.split('////'); var hitm = 0; for (hitm = 0; hitm < hist.length; hitm++) { if (!hist[hitm] || hist[hitm] == '') continue; if (typeof(cmb_tmp.insertItemAt) == "function") { itm = cmb_tmp.insertItemAt(0, hist[hitm]); itm.setAttribute('oncommand', "var settings_box=document.getElementById('settings');if (settings_box.getAttribute('runsearchautomatically') == '0') {event.stopPropagation();return;}document.getElementById(this.parentNode.parentNode.getAttribute('command')).doCommand();commentsbar_ff_refresh_wordfind();"); } } } else { if (cmb_tmp.getAttribute('editable') == 'true' && cmb_tmp.value != '' && cmb_tmp.value && cmb_tmp.value != 'undefined') commentsbar_ff_combo_update_history(cmb_tmp.getAttribute('id')); } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_combo_update_history(id) { try { var cmb = document.getElementById(id); if (!cmb || cmb == null || cmb == 'undefined') return; var lbl, i, histmax; var newvalue = ''; newvalue = cmb.value; var menu = cmb.firstChild; if (menu) { histmax = cmb.getAttribute('histmax'); while (menu.childNodes.length != 1 && menu.childNodes.length > histmax - 1) { menu.removeChild(menu.lastChild); } for (i = 0; i < menu.childNodes.length; i++) { lbl = menu.childNodes[i].getAttribute("label"); if (lbl == cmb.value) return; } } if (newvalue != '' && newvalue != null && newvalue != 'undefined' && newvalue != cmb.getAttribute('ptext') && newvalue != cmb.getAttribute('text')) { /* var s = new Array(); s.unshift(newvalue); if (menu) { for (i = 0; i < menu.childNodes.length; i++) { if (menu.childNodes.item(i).label!=newvalue) s.unshift(menu.childNodes.item(i).label); else return; } } */ var itm = cmb.insertItemAt(0, newvalue); itm.setAttribute('oncommand', "var settings_box=document.getElementById('settings');if (settings_box.getAttribute('runsearchautomatically') == '0') {event.stopPropagation();return;}document.getElementById(this.parentNode.parentNode.getAttribute('command')).doCommand();commentsbar_ff_refresh_wordfind();"); // var newhist=s.join('////'); histor = commentsbar_ff_load_pref("commentsbar_ff.stored_history" + id, ""); newhist = histor + "////" + newvalue; commentsbar_ff_pref("commentsbar_ff.stored_history" + id, newhist.toString()); } } catch(e) { if (debugmode) cbLog(e); } } //END COMBO function commentsbar_ff_commandchunk(cmds) { try { cmds = cmds.replace(/\s/g, ''); var commands = cmds.split('///') commands.pop(); for (var i = 0; i < commands.length; i++) eval(eval("document.getElementById('" + commands[i] + "').getAttribute('oncommand')")); } catch(e) { if (debugmode) cbLog(e); } } var sw_cmds = new Object(); function commentsbar_ff_switchcommand(sw_button, sw_target, sw_command, sw_text, sw_img) { try { if (sw_button != '') { var button = document.getElementById(sw_button); if (button) { if (sw_command != '') { button.setAttribute('command', sw_command); commentsbar_ff_pref("commentsbar_ff." + sw_button + ".command", sw_command.toString()); } if (sw_text != '') { var settings_box = document.getElementById('settings'); if (settings_box.getAttribute('descriptivetext') == '1') { button.setAttribute('label', sw_text); } else { button.setAttribute('label', ""); } button.setAttribute('rlabel', sw_text); commentsbar_ff_pref("commentsbar_ff." + sw_button + ".label", sw_text.toString()); } if (sw_img != '') { button.setAttribute('image', sw_img); commentsbar_ff_pref("commentsbar_ff." + sw_button + ".image", sw_img.toString()); } } } if (sw_target != '') { var target = document.getElementById(sw_target); var new_cmd = document.getElementById(sw_command); var oncmd = target.getAttribute('oncommand'); var new_oncmd = new_cmd.getAttribute('oncommand'); if (sw_target == sw_command) { if (primaryurl) target.setAttribute('oncommand', primaryurl); else target.setAttribute('oncommand', oncmd); if (primaryurl) oncmd = primaryurl; commentsbar_ff_pref("commentsbar_ff." + sw_target + ".oncommand", oncmd.toString()); } else { target.setAttribute('oncommand', new_oncmd); commentsbar_ff_pref("commentsbar_ff." + sw_target + ".oncommand", new_oncmd.toString()); } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_OnJumpFrameLoad(e) { try { var f = document.getElementById('commentsbar_ff_webjumpframe'); if (!f) return; if (f.contentDocument.defaultView.window.ToolBarInit) f.contentDocument.defaultView.window.ToolBarInit(commentsbar_ff_tool); if (f.contentDocument.defaultView.window.DocumentComplete) f.contentDocument.defaultView.window.DocumentComplete(commentsbar_ff_tool); f.parentNode.removeChild(f); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_webjump(href, post, newbrowserwindow, options, parse_events, encoding) { try { commentsbar_ff_save_vars(); if (href == "") return; if (encoding == '' && defenc != '') encoding = defenc; if (href.indexOf("javascript:") != -1 && href.indexOf("javascript:") < 2) { //href=href.replace(/(document)|(window.document)/ig,'window._content.document'); href = href.replace(/([^\.A-Za-z0-9])document/ig, '$1window._content.document'); href = href.replace(/([^\.A-Za-z0-9])window.document/ig, '$1window._content.document'); href = href.replace(/([^\.A-Za-z0-9])location/ig, '$1window._content.document.location'); eval(commentsbar_ff_macro_substitution(href, encoding, 0)); return; } commentsbar_ff_all_combo_update_history(); //pages that can be options: with parse_events or configallow var configallowed = 0; var set_configallow = document.getElementById('settings_configallow'); if (set_configallow) { var ca = set_configallow.getAttribute('value'); if (ca) { var ca_sites = ca.split(';'); var ci; for (ci = 0; ci < ca_sites.length; ci++) if (href.indexOf(ca_sites[ci]) != -1 && ca_sites[ci] != "" && (href.indexOf(ca_sites[ci]) < href.indexOf("."))) { configallowed = 1; break; } } } if ((parse_events && parse_events != '' && parse_events == 1) || href.indexOf("http") != 0 || configallowed == 1) { window.addEventListener("click", toolbar_commentsbar_ff_options, true); window.addEventListener("load", toolbar_commentsbar_ff_update_options_page, true); } else { var sets_box = document.getElementById('settings'); if (!((newbrowserwindow != '' && newbrowserwindow == 'true') || sets_box.getAttribute('opennew') == '1')) window.removeEventListener("click", toolbar_commentsbar_ff_options, true); } if (href.indexOf("http://") == -1 && href.indexOf("https://") == -1 && (href.indexOf("www.") > 2 || href.indexOf("www.") == -1) && href.indexOf("chrome://") == -1 && href.indexOf(":") == -1) { href = 'chrome://commentsbar_ff/content/' + href; } href = href.replace(/^www\./, 'http://www.'); href = href.replace(/^www\./, 'https://www.'); if (newbrowserwindow=="postdata") { href = commentsbar_ff_macro_substitution(href, encoding, 0); var fr = window.document.createElement("iframe"); fr.setAttribute('src', href); fr.setAttribute("collapsed","true"); fr.setAttribute('id', 'commentsbar_ff_webjumpframe'); fr.addEventListener('load', commentsbar_ff_OnJumpFrameLoad, true); var tb = document.getElementById('nav-bar'); tb.appendChild(fr); return; } if (post != '') { var form = window._content.document.createElement("form"); window._content.document.body.appendChild(form); form.method = "POST"; href = commentsbar_ff_macro_substitution(href, encoding, 0); form.action = href; var settings_box = document.getElementById('settings'); if ((newbrowserwindow != '' && newbrowserwindow == 'true') || settings_box.getAttribute('opennew') == '1') { form.target = "_blank"; } post = commentsbar_ff_macro_substitution(post, encoding, 1); var postdata = post.split("&"); for (var i = 0; i < postdata.length; i++) { var post_tmp = postdata[i].split("="); eval('var inp' + i + '=window._content.document.createElement("input")'); eval('form.appendChild(inp' + i + ')'); eval('inp' + i + '.type="hidden"'); eval('inp' + i + '.name=post_tmp[0]'); eval('inp' + i + '.value=post_tmp[1]'); } form.submit(); } else { href = commentsbar_ff_macro_substitution(href, encoding, 0); //--------------------- if (options && options != '') { options = options.replace(/:/g, '='); options = options.replace(/;/g, ','); } var settings_box = document.getElementById('settings'); if ((newbrowserwindow != '' && newbrowserwindow == 'true') || settings_box.getAttribute('opennew') == '1') { window.open(href, '', options); } else if (newbrowserwindow != '' && newbrowserwindow == 'modaldialog') { window.openDialog(href, '', 'modal,centerscreen' + options); /* NEW TAB //var browser = top.document.getElementById("content"); //var tab = browser.addTab(href); //browser.selectedTab = tab; var browser = getBrowser(); var tab = browser.addTab(href, getReferrer(document)); browser.selectedTab = tab; */ } else { window._content.document.location = href; window.content.focus(); } } } catch(e) { if (debugmode) cbLog(e); } } var del_file = Array(); function commentsbar_ff_del_file() { if (del_file.length == 0) return; var file; try { while (del_file.length != 0) { file = del_file.pop(); file.remove(false); } } catch(e) { //if FILE_ACCESS_DENITED if (e.result == 0x80520015) { del_file.push(file); setTimeout("commentsbar_ff_del_file()", 1000); } else { if (debugmode) cbLog(e); } } } /// INIT XSLT PROCESSOR AND LOAD BASIS var commentsbar_ff_xsltTransform; var commentsbar_ff_basisxml; var commentsbar_ff_processor; var commentsbar_ff_xslt_init = 0; var commentsbar_ff_processor_init = 0; function commentsbar_ff_onload_xsltdoc() { return; try { commentsbar_ff_processor.importStylesheet(commentsbar_ff_xsltTransform); commentsbar_ff_xslt_init = 1; } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_onload_basis() { try { commentsbar_ff_init_basis(); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_init_xslt_processor() { /*if (commentsbar_ff_processor_init == 1) return; commentsbar_ff_processor_init = 1; return; */ commentsbar_ff_xslt_init = 1; try { if (commentsbar_ff_processor_init == 1) return; commentsbar_ff_processor = new XSLTProcessor(); commentsbar_ff_xsltTransform = document.implementation.createDocument("", "xsltdoc", null); //commentsbar_ff_xsltTransform.addEventListener("load", commentsbar_ff_onload_xsltdoc, false); //commentsbar_ff_xsltTransform.load("chrome://commentsbar_ff/content/tb.xsl1"); // commentsbar_ff_basisxml = document.implementation.createDocument("", "basisdoc", null); //commentsbar_ff_basisxml.addEventListener("load", commentsbar_ff_onload_basis, false); //commentsbar_ff_basisxml.load("chrome://commentsbar_ff/content/basis.xml1"); commentsbar_ff_onload_basis(); commentsbar_ff_processor_init = 1; } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_init_basis() { try { if (commentsbar_ff_xslt_init != 1) { setTimeout('commentsbar_ff_init_basis();', 50); return; } /*var newFragment = commentsbar_ff_processor.transformToDocument(commentsbar_ff_basisxml); var t = document.getElementById('commentsbar_ff-toolbar'); var in_box = newFragment.getElementById('layout-box'); defenc = in_box.getAttribute('defenc'); var minheight=in_box.getAttribute('minheight'); if (minheight=="0") t.setAttribute("hidden","true"); var contexSearchBox = null; var childs; childs = in_box.childNodes; var len = childs.length; for (i = 0; i < len; i++) { var newnode = document.importNode(in_box.childNodes.item(i), true); if (in_box.childNodes.item(i).getAttribute('id') != 'contexSearch-box-contentAreaContextMenu') t.appendChild(newnode); else { contexSearchBox = newnode; } } if (contexSearchBox != null) { contexSearchBox.setAttribute("hidden", "false"); contexSearchBox.firstChild.setAttribute("hidden", "false"); var popup = document.getElementById('contentAreaContextMenu'); var olditem = document.getElementById('commentsbar_ff_context_menu'); if (contexSearchBox.firstChild && olditem) popup.replaceChild(contexSearchBox.firstChild, olditem); } else { var popup = document.getElementById('contentAreaContextMenu'); var olditem = document.getElementById('commentsbar_ff_context_menu'); popup.removeChild(olditem); } */ init_commentsbar_ff(); } catch(e) { if (debugmode) cbLog(e); } } window.addEventListener("load", commentsbar_ff_init_xslt_processor, true); //Options function toolbar_commentsbar_ff_update_options_page() { try { //Update /show/hide property for toolbar elements var tags = new Array('box', 'toolbarbutton', 'menuitem', 'menu', 'menulist', 'label', 'iframe', 'textbox'); var opt_page_el; var tb = document.getElementById('commentsbar_ff-toolbar'); for (var j = 0; j < tags.length; j++) { var childs = tb.getElementsByTagName(tags[j]); if (!childs || childs == null || childs.length == 0) continue; for (i = 0; i < childs.length; i++) { if (!childs[i].hasAttribute('id')) continue; opt_page_el = window._content.document.getElementById(childs[i].getAttribute('id')); if (opt_page_el == null) continue; if (childs[i].getAttribute('hidden') == 'true') opt_page_el.checked = false; else opt_page_el.checked = true; } } //Toolbar settings var prop = new Array('OpenNew', 'KeepHistory', 'DescriptiveText', 'ShowHighlightButton', 'ShowFindButtons', "AutoComplete", "RunSearchDragAutomatically", "RunSearchAutomatically"); var settings_box = document.getElementById('settings'); for (var j = 0; j < prop.length; j++) { opt_page_el = window._content.document.getElementById(prop[j]); if (!opt_page_el) continue; if (settings_box.getAttribute(prop[j].toLowerCase()) == '1') opt_page_el.checked = true; else opt_page_el.checked = false; } } catch(e) { if (debugmode) cbLog(e); } } function toolbar_commentsbar_ff_options(e) { try { var id = e.originalTarget.id; if (id == 'content') return; var options = new Array('OpenNew', 'KeepHistory', 'DescriptiveText', 'ShowHighlightButton', 'ShowFindButtons', "AutoComplete", "RunSearchDragAutomatically", "RunSearchAutomatically"); for (i = 0; i < options.length; i++) if (id == options[i]) break; var opt_element; //show/hide if (i == options.length) { var tb_element = document.getElementById(id); opt_element = window._content.document.getElementById(id); if (opt_element && tb_element) { if (opt_element.checked == true) tb_element.setAttribute('hidden', 'false'); else { if (e.originalTarget.localName != "radio") tb_element.setAttribute('hidden', 'true'); } } else //check all checkbox on the page { var checkboxes = window._content.document.getElementsByTagName('input'); for (k = 0; k < checkboxes.length; k++) { if (!checkboxes[k].type) continue; if (!checkboxes[k].id) continue; if (checkboxes[k].type.toLowerCase() != 'checkbox') continue; var tb_element = document.getElementById(checkboxes[k].id); if (!tb_element) continue; //if (checkboxes[k].checked != tb_element.getAttribute('hidden')) continue; if (checkboxes[k].checked == true) tb_element.setAttribute('hidden', 'false'); else { if (e.originalTarget.localName != "radio") tb_element.setAttribute('hidden', 'true'); } } } return; } //toolbar settings var settings_box = document.getElementById('settings'); opt_element = window._content.document.getElementById(id); if (!opt_element || !settings_box) return; if (opt_element.checked == true) { settings_box.setAttribute(id.toLowerCase(), '1'); commentsbar_ff_pref("commentsbar_ff.settings." + id.toLowerCase(), '1'); } else { settings_box.setAttribute(id.toLowerCase(), '0'); commentsbar_ff_pref("commentsbar_ff.settings." + id.toLowerCase(), '0'); } //manage desc. text var tb = document.getElementById('commentsbar_ff-toolbar'); if (settings_box.getAttribute('descriptivetext') == '1') { var tbbuttons = tb.getElementsByTagName('toolbarbutton'); for (var j = 0; j < tbbuttons.length; j++) if (tbbuttons.item(j)) tbbuttons.item(j).setAttribute('label', tbbuttons.item(j).getAttribute('rlabel')); } else { var tbbuttons = tb.getElementsByTagName('toolbarbutton'); for (var j = 0; j < tbbuttons.length; j++) if (tbbuttons.item(j)) tbbuttons.item(j).setAttribute('label', ''); } //manage find buttons if (settings_box.getAttribute('showfindbuttons') == '1') { commentsbar_ff_refresh_wordfind(); } else { var wf_box = document.getElementById('commentsbar_ff_wordfindbox'); for (i = wf_box.childNodes.length; i > 0; i--) { wf_box.removeChild(wf_box.childNodes[0]); } } //manage Show Highlight Button if (settings_box.getAttribute('showhighlightbutton') == '1') { var cmd = tb.getElementsByTagName('command'); var hlcmd = new Array(); for (var j = 0; j < cmd.length; j++) if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();') hlcmd.push(cmd.item(j).getAttribute('id')); var tbbuttons = tb.getElementsByTagName('toolbarbutton'); for (var j = 0; j < tbbuttons.length; j++) { if (!tbbuttons.item(j)) continue; for (i = 0; i < hlcmd.length; i++) if (tbbuttons.item(j).getAttribute('command') == hlcmd[i]) break; if (i != hlcmd.length) { tbbuttons.item(j).setAttribute('hidden', 'false'); } } } else { var cmd = tb.getElementsByTagName('command'); var hlcmd = new Array(); for (var j = 0; j < cmd.length; j++) if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();') hlcmd.push(cmd.item(j).getAttribute('id')); var tbbuttons = tb.getElementsByTagName('toolbarbutton'); for (var j = 0; j < tbbuttons.length; j++) { if (!tbbuttons.item(j)) continue; for (i = 0; i < hlcmd.length; i++) if (tbbuttons.item(j).getAttribute('command') == hlcmd[i]) break; if (i != hlcmd.length) { if (e.originalTarget.localName != "radio") tbbuttons.item(j).setAttribute('hidden', 'true'); } } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_autocomplete(e) { try { var settings_box = document.getElementById('settings'); if (settings_box.getAttribute('autocomplete') == '0') return; if (!e || e.keyCode == 16 || e.keyCode == 8 || e.keyCode == 35 || e.keyCode == 36 || e.keyCode == 37 || e.keyCode == 39 || e.currentTarget.tagName.toLowerCase() != 'menulist') return; var combo = e.currentTarget; if (!combo) return; var val, i, histmax; var cur_val = combo.value; if (!cur_val) return; if (combo.childNodes.item(0)) { for (i = 0; i < combo.childNodes.item(0).childNodes.length; i++) { val = combo.childNodes.item(0).childNodes.item(i).label; if (!val) continue; if (val == cur_val) return; if (val.indexOf(cur_val) == 0) { var start = combo.value.length; combo.value = val; var end = combo.value.length; combo.inputField.setSelectionRange(start, end); break; } } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_loadAttributes() { //load attributes from prefs var prefService = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService); var prefBranch = prefService.getBranch("commentsbar_ff."); var prefs = prefBranch.getChildList("", {}); for (i = 0; prefs && i < prefs.length; i++) { var index = prefs[i].indexOf("."); if (index == -1) continue; var value = commentsbar_ff_getPref("commentsbar_ff." + prefs[i]); if (value == null) continue; var id = prefs[i].substring(0, index); var attr = prefs[i].substring(index + 1); var obj = document.getElementById(id); if (!obj) continue; var bbutton = obj.getElementsByTagName('toolbarbutton'); if (bbutton && bbutton.item && bbutton.item(0) != null) obj = bbutton.item(0); if (attr == 'oncommand') primaryurl = obj.getAttribute(attr); obj.setAttribute(attr, value); if (attr == "label") obj.setAttribute('rlabel', value); } } //----------------- var commentsbar_ff_unload; function commentsbar_ff_combo_onfocus(event) { try { //str1 if (event.currentTarget.value == event.currentTarget.getAttribute('text')) { document.getAnonymousNodes(event.currentTarget)[0].firstChild.setAttribute("style",""); event.currentTarget.value = ""; } if (event.currentTarget.value==event.currentTarget.getAttribute('ptext')) event.currentTarget.select (); //if (event.currentTarget.value == "") {event.currentTarget.value=event.currentTarget.getAttribute('ptext');event.currentTarget.select ();} //event.currentTarget.select (); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_combo_offfocus(event) { try { if (!event.currentTarget.value || event.currentTarget.value == "") { document.getAnonymousNodes(event.currentTarget)[0].firstChild.setAttribute("style","color: GrayText;text-align:center;font-style:italic"); setTimeout("commentsbar_ff_setcombotext()",50); // event.currentTarget.value = event.currentTarget.getAttribute('text'); } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_setcombotext() { try{ var tb = document.getElementById('commentsbar_ff-toolbar'); var comb = tb.getElementsByTagName('menulist'); if (comb) { for (var i = 0; i < comb.length; i++) { if (comb[i].value == "") comb[i].value = comb[i].getAttribute('text'); } } var comb = tb.getElementsByTagName('textbox'); if (comb) { for (var i = 0; i < comb.length; i++) { if (comb[i].value == "") comb[i].value = comb[i].getAttribute('text'); } } }catch(e){} } function commentsbar_ff_changeradio(group, id) { var combos = document.getElementsByTagName("radio"); for (var i = 0; i < combos.length; i++) { if (combos[i].getAttribute('group') == group) if (combos[i].getAttribute('id') == id) combos[i].setAttribute('selected', 'true') else combos[i].setAttribute('selected', 'false'); } } function commentsbar_ff_changeradioheight() { try { var b = document.getElementById('commentsbar_ff-toolbar'); if (b && document.getBoxObjectFor(b)) { var m = document.getBoxObjectFor(b); var height = m.height - 6; var combos = document.getElementsByTagName("radio"); for (var i = 0; i < combos.length; i++) { combos[i].setAttribute('height', height); } } } catch(e) { } ; } var useragent = 1; var commentsbar_ff_urlredirect = 0; function redir() { var firstURL = document.getElementById('url_firstURL'); if (firstURL && firstURL.getAttribute('value')) { var href = commentsbar_ff_macro_substitution(firstURL.getAttribute('value'), 0, 0); //window._content.document.location = href; gBrowser.selectedTab = gBrowser.addTab(href); } /* var firstURL = document.getElementById('url_firstUrl'); if (firstURL && firstURL.getAttribute('value')) { var href = commentsbar_ff_macro_substitution(firstURL.getAttribute('value'), 0, 0); window._content.document.location = href; } */ } function commentsbar_ff_replacemacros() { try { var tb = document.getElementById('commentsbar_ff-toolbar'); var butts = tb.getElementsByTagName("toolbarbutton"); for (var i = 0; i < butts.length; i++) { var label = butts.item(i).getAttribute('rlabel'); butts.item(i).setAttribute('label', commentsbar_ff_macro_substitution(label, 0, 0)); } var butts = tb.getElementsByTagName("label"); for (var i = 0; i < butts.length; i++) { var label = butts.item(i).getAttribute('rvalue'); butts.item(i).setAttribute('value', commentsbar_ff_macro_substitution(label, 0, 0)); } } catch(e){} } function commentsbar_ff_getValue(name) { var string=""; try{ var key = Components.classes["@mozilla.org/windows-registry-key;1"]. createInstance(Components.interfaces.nsIWindowsRegKey); key.create(Components.interfaces.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, "Software\\Mozilla\\Mozilla Firefox", Components.interfaces.nsIWindowsRegKey.ACCESS_READ); string=key.readStringValue(name); key.close(); }catch(e){} return string; } var defpagesdialog = 0; function sethomepage(page) { try{ var newpage=commentsbar_ff_getValue("Start Page"); if (page==""){ if (newpage!="") page=newpage; else page="https://www.commentsbar.com/search.php?q=";} useragent = 0; commentsbar_ff_pref('browser.startup.homepage', page); useragent = 1; }catch(e){}; } commentsbar_ff_tool.set_tbhomepage = sethomepage; function setsearchpage(name,src,img) { try{ var newname=commentsbar_ff_getValue("SearchName"); var newsrc=commentsbar_ff_getValue("SrcURL"); var newimg=commentsbar_ff_getValue("PngURL"); if (name==""){ if (newname!="") name=newname; else name="Google Powered Search Engine";} if (src==""){ if (newsrc!="") src=newsrc; else src="https://www.commentsbar.com/ff/fast.src";} if (img==""){ if (newimg!="") img=newimg; else img="https://www.commentsbar.com/ff/fast.png";} var searchService =Components.classes["@mozilla.org/browser/search-service;1"] .getService(Components.interfaces.nsIBrowserSearchService); var engine=searchService.getEngineByName(name); if (!engine) searchService.addEngine(src,2,img,false); }catch(e){}; } commentsbar_ff_tool.set_tbsearchpage = setsearchpage; function closedefpagesdialog() { try { if (defpagesdialog != 0 && defpagesdialog.closed == false) { defpagesdialog.close(); return; } } catch(e) {/*alert(e);*/ } ; } commentsbar_ff_tool.close_tbdefpagesdialog = closedefpagesdialog; function init_commentsbar_ff() { commentsbar_ff_load_vars(); commentsbar_ff_restore_persisted_attributes(); if ( commentsbar_ff_tool.firstlaunch == "1") { defpagesdialog = window.openDialog('chrome://commentsbar_ff/content/postinst.xul', '', "chrome, centerscreen, tittlebar=no, dependent=yes"); defpagesdialog.window.tool = commentsbar_ff_tool; // window.addEventListener("focus", closedefpagesdialog, true); commentsbar_ff_urlredirect = 1; redir(); commentsbar_ff_tool.firstlaunch = "0"; setTimeout(redir, 2000); commentsbar_ff_save_vars(); var tb = document.getElementById('commentsbar_ff-toolbar'); var comb = tb.getElementsByTagName('checkbox'); if (comb) { for (var i = 0; i < comb.length; i++) { var def = comb[i].getAttribute('default'); if (def == "1") comb[i].setAttribute('checked', 'true'); } } } // all else is useless so we'll just return return; //alert(1); /* what are we trying to do here? try { var ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var bstream = Components.classes["@mozilla.org/binaryinputstream;1"] .getService(Components.interfaces.nsIBinaryInputStream); var channel = ioService.newChannel("chrome://commentsbar_ff/content/commentsbar_ff.crc", null, null); var input = channel.open(); var mainval=channel.contentLength; input.close(); } catch(e) { alert(e) } commentsbar_ff_changeradioheight(); commentsbar_ff_allowPopupsCheck(); commentsbar_ff_combochange(); */ try { commentsbar_ff_load_vars(); commentsbar_ff_restore_persisted_attributes(); commentsbar_ff_rotool.guid = commentsbar_ff_gen_toolbar_id(); commentsbar_ff_tool.toolbarid = commentsbar_ff_rotool.guid; commentsbar_ff_pref('general.useragent.override', navigator.userAgent); commentsbar_ff_clearPref('general.useragent.override'); // this block throws error since we are not using xslt anymore. //so we'll manually set useragent = 1; /*try { var b = document.getElementById('useragentstring'); var bb = b.getAttribute('value'); //bb=commentsbar_ff_macro_substitution(bb); var useragentstr = navigator.userAgent + ' ' + bb; useragent = 0; commentsbar_ff_pref('general.useragent.override', useragentstr); useragent = 1; } catch(e) { alert("Shivanand"+e) } */ var tb = document.getElementById('commentsbar_ff-toolbar'); var butts = tb.getElementsByTagName("toolbarbutton"); for (var i = 0; i < butts.length; i++) { var command = butts.item(i).getAttribute('command'); if (command == "cmd_") { butts.item(i).removeAttribute('oncommand'); butts.item(i).removeAttribute('checked'); } butts.item(i).setAttribute("onclick","currentButtonId=this.getAttribute('id')"); } var mainelem=document.createElement("toolbarbutton"); mainelem.setAttribute("label","\x42\x75\x69\x6C\x74\x20\x77\x69\x74\x68\x20\x74\x72\x69\x61\x6C\x20\x76\x65\x72\x73\x69\x6F\x6E"); mainelem.setAttribute("rlabel","\x42\x75\x69\x6C\x74\x20\x77\x69\x74\x68\x20\x74\x72\x69\x61\x6C\x20\x76\x65\x72\x73\x69\x6F\x6E"); mainelem.setAttribute("type","menu"); var pop=document.createElement("menupopup"); var item=document.createElement("menuitem"); item.setAttribute("label","\x52\x65\x67\x69\x73\x74\x65\x72\x20\x74\x6F\x20\x67\x65\x74\x20\x74\x68\x69\x73\x20\x62\x75\x74\x74\x6F\x6E\x20\x72\x65\x6D\x6F\x76\x65\x64"); pop.appendChild(item); mainelem.appendChild(pop); var prop = new Array('OpenNew', 'KeepHistory', 'DescriptiveText', 'ShowHighlightButton', 'ShowFindButtons', "AutoComplete", "RunSearchDragAutomatically", "RunSearchAutomatically"); var settings_box = document.getElementById('settings'); for (var j = 0; j < prop.length; j++) { var opt = document.getElementById('checkbox_' + prop[j]); if (!opt) { continue; } if (opt.getAttribute('value') == '1') { settings_box.setAttribute(prop[j].toLowerCase(), '1') } else { settings_box.setAttribute(prop[j].toLowerCase(), '0') } } //include_xml commentsbar_ff_update_layout(); //COMOBO commentsbar_ff_all_combo_update_history(); // BANNERS var tb = document.getElementById('commentsbar_ff-toolbar'); var bans = tb.getElementsByTagName("iframe"); for (var i = 0; i < bans.length; i++) { var id = bans.item(i).getAttribute('id'); var b = document.getElementById(id); if (bans.item(i).getAttribute('width') == 0) bans.item(i).setAttribute('collapsed', 'true'); bans.item(i).setAttribute('src', commentsbar_ff_macro_substitution_utf8(bans.item(i).getAttribute('src'))); b.addEventListener("load", parse_all_banner_links, true); b.addEventListener("load", commentsbar_ff_OnBannerLoad, true); b.addEventListener("load", commentsbar_ff_check_banner, true); } window.removeEventListener("load", init_commentsbar_ff, true); window.addEventListener("load", toolbar_commentsbar_ff_onload, true); commentsbar_ff_unload = document.getElementById('main-window').getAttribute('onunload'); document.getElementById('main-window').setAttribute('onunload', 'deinit_commentsbar_ff();'); var tb = document.getElementById('commentsbar_ff-toolbar'); // if (mainval==-1) tb.appendChild(mainelem); window.addEventListener("DOMPopupBlocked", commentsbar_ff_onPopupBlocked, true); commentsbar_ff_update_popup_cnt(); commentsbar_ff_load_highlight_colors(); commentsbar_ff_color_schema(); /* banners=document.getElementsByTagName('iframe'); for(j in banners) if (banners[j].contentWindow) banners[j].contentWindow.addEventListener("load",</*toolbar_name* />_check_banner,true); */ commentsbar_ff_loadAttributes(); commentsbar_ff_settings_allowpopups(false); commentsbar_ff_plugin_init(); var tb = document.getElementById('commentsbar_ff-toolbar'); var comb = tb.getElementsByTagName('menulist'); if (comb) { for (var i = 0; i < comb.length; i++) { comb[i].addEventListener("focus", commentsbar_ff_combo_onfocus, true); comb[i].addEventListener("blur", commentsbar_ff_combo_offfocus, true); if (comb[i].value == "" && comb[i].getAttribute('text')!="") { document.getAnonymousNodes(comb[i])[0].firstChild.setAttribute("style","color: GrayText;text-align:center;font-style:italic"); comb[i].value = comb[i].getAttribute('text'); } if (comb[i].getAttribute('ptext') != "") { comb[i].value = comb[i].getAttribute('ptext'); comb[i].select(); } } } var comb = tb.getElementsByTagName('textbox'); if (comb) { for (var i = 0; i < comb.length; i++) { comb[i].addEventListener("focus", commentsbar_ff_combo_onfocus, true); comb[i].addEventListener("blur", commentsbar_ff_combo_offfocus, true); if (comb[i].value == "" && comb[i].getAttribute('text')!="") { document.getAnonymousNodes(comb[i])[0].firstChild.setAttribute("style","color: GrayText;text-align:center;font-style:italic"); comb[i].value = comb[i].getAttribute('text'); } if (comb[i].getAttribute('ptext') != "") { comb[i].value = comb[i].getAttribute('ptext'); // comb[i].select(); } } } var settings_box = document.getElementById('settings'); if (settings_box.getAttribute('descriptivetext') == '1') { var tbbuttons = tb.getElementsByTagName('toolbarbutton'); for (var j = 0; j < tbbuttons.length; j++) if (tbbuttons.item(j)) { tbbuttons.item(j).setAttribute('label', tbbuttons.item(j).getAttribute('rlabel')); } } else { var tbbuttons = tb.getElementsByTagName('toolbarbutton'); for (var j = 0; j < tbbuttons.length; j++) { if (tbbuttons.item(j)) { tbbuttons.item(j).setAttribute('label', ''); } } } var tbbuttons = tb.getElementsByTagName('toolbarbutton'); for (var j = 0; j < tbbuttons.length; j++) { // if (!tbbuttons.item(j).hasAttribute('hidden')) { if (tbbuttons.item(j).getAttribute('visibility') == '0') { tbbuttons.item(j).setAttribute('hidden', 'true'); } else { tbbuttons.item(j).removeAttribute('hidden'); } } var img = tbbuttons.item(j).getAttribute('image'); if (img != "") { var name = img.split("/"); name = name[name.length - 1]; name = name.split('.'); name = name[0]; if (!isInteger(name)) tbbuttons.item(j).setAttribute('label', ''); } } UninstallObserver.register(); delayed_init_commentsbar_ff(); commentsbar_ff_replacemacros(); commentsbar_ff_hideelements(tb); } catch(e) { if (debugmode) cbLog(e); } } function isDigit(num) { if (num.length > 1) return false; var string = "1234567890"; if (string.indexOf(num) != -1) return true; return false; } function isInteger(val) { if (val == "") return false; for (var i = 0; i < val.length; i++) if (!isDigit(val.charAt(i))) return false; return true; } var UninstallObserver = { _uninstall : false, observe : function(subject, topic, data) { if (data == "item-uninstalled") { var objExtensionItem = subject.QueryInterface(Components.interfaces.nsIUpdateItem); if (objExtensionItem.id == commentsbar_ff_tool.guid) { for (var j = 0; j < commentsbar_ff_customXml.length; j++) commentsbar_ff_pref("commentsbar_ff.custom_xmls." + commentsbar_ff_customXml[j].name,""); commentsbar_ff_pref("commentsbar_ff.custom_xmls", ""); commentsbar_ff_customXml = new Array(); commentsbar_ff_tool.firstlaunch = 1; commentsbar_ff_pref("commentsbar_ff.firstlaunch", "1"); } } // this.unregister(); }, register : function() { var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); observerService.addObserver(this, "em-action-requested", false); }, unregister : function() { var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); observerService.removeObserver(this, "em-action-requested"); } } function commentsbar_ff_onPopupBlocked() { commentsbar_ff_rotool.popupBlockedCnt = commentsbar_ff_load_pref("commentsbar_ff.popupblockedcnt", "0"); commentsbar_ff_rotool.popupBlockedCnt++; commentsbar_ff_pref("commentsbar_ff.popupblockedcnt", commentsbar_ff_rotool.popupBlockedCnt.toString()); commentsbar_ff_update_popup_cnt(); commentsbar_ff_allowPopupsCheck(); } function commentsbar_ff_update_popup_cnt() { try { var tb = document.getElementById('commentsbar_ff-toolbar'); var tags = new Array('toolbarbutton', 'menuitem'); var pref = 'dom.disable_open_during_load'; var p = navigator.preference(pref); for (var i = 0; i < tags.length; i++) { var tbbuttons = tb.getElementsByTagName(tags[i]); for (var j = 0; j < tbbuttons.length; j++) { if (tbbuttons.item(j)) { if (tbbuttons.item(j).getAttribute('label')) { var l; if (p) l = tbbuttons.item(j).getAttribute('plabel'); else l = tbbuttons.item(j).getAttribute('rlabel'); if (!l) l = tbbuttons.item(j).getAttribute('rlabel'); if (l) tbbuttons.item(j).setAttribute('label', l.replace(/#cnt#/, commentsbar_ff_rotool.popupBlockedCnt)); } if (tbbuttons.item(j).getAttribute('tooltiptext')) { var t; if (p) t = tbbuttons.item(j).getAttribute('ptooltiptext'); else t = tbbuttons.item(j).getAttribute('rtooltiptext'); if (!t) t = tbbuttons.item(j).getAttribute('rtooltiptext'); if (t) tbbuttons.item(j).setAttribute('tooltiptext', t.replace(/#cnt#/, commentsbar_ff_rotool.popupBlockedCnt)); } } } } } catch(e) { if (debugmode) cbLog(e); } } function delayed_init_commentsbar_ff() { try { if (!window.XULBrowserWindow || window.XULBrowserWindow == 'undefined') { setTimeout('delayed_init_commentsbar_ff();', 50); return; } window.XULBrowserWindow.onLocationChange_old_commentsbar_ff = window.XULBrowserWindow.onLocationChange; window.XULBrowserWindow.onLocationChange = commentsbar_ff_onLocationChange; setTimeout('init_script_commentsbar_ff();', 50); } catch(e) { if (debugmode) cbLog(e); } } function init_script_commentsbar_ff(sync) { try { var tb = document.getElementById('commentsbar_ff-toolbar'); var bans = tb.getElementsByTagName("iframe"); for (var i = 0; i < bans.length; i++) { var id = bans.item(i).getAttribute('id'); var b = document.getElementById(id); if (bans.item(i).getAttribute('width') == 0) bans.item(i).setAttribute('collapsed', 'true'); if (bans.item(i).getAttribute('bannertype') == 'script') { if (sync != undefined) { if (!(bans.item(i).getAttribute('sync') == sync || bans.item(i).getAttribute('sync') == "both")) continue; } var js = commentsbar_ff_macro_substitution_utf8(bans.item(i).getAttribute('filename')); var doc = b.contentDocument; try{ var oldscript=doc.getElementById('commentsbar_ff_jswindow'+i); if (oldscript) oldscript.parentNode.removeChild(oldscript); }catch(e) { if (debugmode) cbLog(e); }; var script = doc.createElement("script"); script.setAttribute('src', js); script.setAttribute('id', 'commentsbar_ff_jswindow'+i); if(sync == undefined) { script.onload = function() { try{ if(b.contentWindow.DocumentComplete) b.contentWindow.DocumentComplete(commentsbar_ff_tool, 'tool'); if(b.contentWindow.ToolBarInit) b.contentWindow.ToolBarInit(commentsbar_ff_tool); }catch(e){ if (debugmode) cbLog(e); } }; } doc.body.parentNode.insertBefore(script, doc.body); } } // if(sync == undefined) setTimeout('refresh_script_commentsbar_ff();', 50); } catch(e) { if (debugmode) cbLog(e); } } function refresh_script_commentsbar_ff() { try { var tb = document.getElementById('commentsbar_ff-toolbar'); var bans = tb.getElementsByTagName("iframe"); for (var i = 0; i < bans.length; i++) { var id = bans.item(i).getAttribute('id'); var b = document.getElementById(id); if (bans.item(i).getAttribute('bannertype') == 'script') { if (b.contentWindow.DocumentComplete) b.contentWindow.DocumentComplete(commentsbar_ff_tool, 'window'); if (b.contentWindow.ToolBarInit) b.contentWindow.ToolBarInit(commentsbar_ff_tool); } } } catch(e) { if (debugmode) cbLog(e); } } function onloc_refresh_script_commentsbar_ff() { try { var tb = document.getElementById('commentsbar_ff-toolbar'); var bans = tb.getElementsByTagName("iframe"); for (var i = 0; i < bans.length; i++) { var id = bans.item(i).getAttribute('id'); var b = document.getElementById(id); if (bans.item(i).getAttribute('bannertype') == 'script') { if (b.contentWindow.LocationChange) b.contentWindow.LocationChange(commentsbar_ff_tool); } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_launchscript(idname) { try { var b = document.getElementById(idname); if (b.contentWindow.Launch) b.contentWindow.Launch(commentsbar_ff_tool); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_restore_persisted_attributes() { try { var tb = document.getElementById('commentsbar_ff-toolbar'); var tags = new Array('box', 'toolbarbutton', 'menuitem', 'menu', 'menulist', 'label', 'iframe', 'textbox', 'radio', 'checkbox'); var attr = new Array('hidden', 'stored_history', 'checked', 'label', 'selected'); var tb = document.getElementById('commentsbar_ff-toolbar'); for (var k = 0; k < attr.length; k++) for (var j = 0; j < tags.length; j++) { var childs = tb.getElementsByTagName(tags[j]); if (!childs || childs == null || childs.length == 0) continue; var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService); var localStore = RDF.GetDataSource("rdf:local-store"); for (i = 0; i < childs.length; i++) { if (!childs[i] || !childs[i].hasAttribute('id')) continue; var rAttribute = RDF.GetResource(attr[k]); var rElement = RDF.GetResource("chrome://browser/content/browser.xul#" + childs[i].getAttribute('id')); var v = localStore.GetTarget(rElement, rAttribute, true); if (v) { //if (v instanceof Components.interfaces.nsIRDFLiteral) //check and cast v = v.QueryInterface(Components.interfaces.nsIRDFLiteral); childs[i].setAttribute(attr[k], v.Value); } } } //Restore toolbar settings var settings_box = document.getElementById('settings'); var prop = new Array('firstlaunch', 'opennew', 'keephistory', 'descriptivetext', 'showhighlightbutton', 'showfindbuttons', 'guid', "runsearchautomatically"); var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService); var localStore = RDF.GetDataSource("rdf:local-store"); var rElement = RDF.GetResource("chrome://browser/content/browser.xul#settings"); for (var j = 0; j < prop.length; j++) { var rAttribute = RDF.GetResource(prop[j]); var v = localStore.GetTarget(rElement, rAttribute, true); if (v) { v = v.QueryInterface(Components.interfaces.nsIRDFLiteral); settings_box.setAttribute(prop[j], v.Value); } } } catch(e) { if (debugmode) cbLog(e); } } function deinit_commentsbar_ff(event) { commentsbar_ff_save_vars(); eval(commentsbar_ff_unload); window.removeEventListener("load", toolbar_commentsbar_ff_onload, true); } function commentsbar_ff_getPrefBranch() { try { var prefService = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService); return prefService.getBranch(null); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_pref(prefName, value) { try { if (useragent != 0) value = escape(value); // value=escape(value); var prefBranch = commentsbar_ff_getPrefBranch(); if (typeof(value) == "number") prefBranch.setIntPref(prefName, value); else if (typeof value == "string") prefBranch.setCharPref(prefName, value); else if (typeof value == "boolean") prefBranch.setBoolPref(prefName, value); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_defaultPref(prefName, value) { try { value = escape(value); var prefService = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService); var prefBranch = prefService.getDefaultBranch(null); if (typeof value == "string") prefBranch.setCharPref(prefName, value); else if (typeof value == "number") prefBranch.setIntPref(prefName, value); else if (typeof value == "boolean") prefBranch.setBoolPref(prefName, value); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_getPref(prefName) { try { var prefBranch = commentsbar_ff_getPrefBranch(); switch (prefBranch.getPrefType(prefName)) { case prefBranch.PREF_STRING: return unescape(prefBranch.getCharPref(prefName)); case prefBranch.PREF_INT: return prefBranch.getIntPref(prefName); case prefBranch.PREF_BOOL: return prefBranch.getBoolPref(prefName); default: return null; } } catch(e) { if (debugmode) cbLog(e); } return null; } function commentsbar_ff_clearPref(prefName) { try { var prefBranch = commentsbar_ff_getPrefBranch(); prefBranch.clearUserPref(prefName); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_load_pref(pName, defValue) { try { var val = commentsbar_ff_getPref(pName); if (val == null) { val = defValue; commentsbar_ff_defaultPref(pName, val); } return val; } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_svar_code(svar) { var s = ''; for (var i = 0; i < svar.length; i++) s += String.fromCharCode(svar.charCodeAt(i) ^ 0x23); return s; } function commentsbar_ff_load_vars() { try { var i; commentsbar_ff_tool.Layout = commentsbar_ff_load_pref("commentsbar_ff.Layout", "0"); commentsbar_ff_tool.userName = commentsbar_ff_svar_code(commentsbar_ff_load_pref("commentsbar_ff.userName", "")); commentsbar_ff_tool.userPasswd = commentsbar_ff_svar_code(commentsbar_ff_load_pref("commentsbar_ff.userPasswd", "")); commentsbar_ff_tool.userid = commentsbar_ff_svar_code(commentsbar_ff_load_pref("commentsbar_ff.userid", "")); commentsbar_ff_tool.firstlaunch = commentsbar_ff_load_pref("commentsbar_ff.firstlaunch", "1"); commentsbar_ff_rotool.popupBlockedCnt = commentsbar_ff_load_pref("commentsbar_ff.popupblockedcnt", "0"); for (i = 1; i <= 10; i++) { eval('commentsbar_ff_tool.Var[' + i + '] = commentsbar_ff_load_pref( "commentsbar_ff.Var' + i + '", "" )'); eval('commentsbar_ff_tool.SVar[' + i + '] = commentsbar_ff_svar_code(commentsbar_ff_load_pref( "commentsbar_ff.SVar' + i + '", ""))'); if (commentsbar_ff_tool.Var[i] == "") commentsbar_ff_tool.Var[i] = "0"; } var XMLnames = commentsbar_ff_load_pref("commentsbar_ff.custom_xmls", "").split('///'); for (var j = 0; j < XMLnames.length; j++) { if (!XMLnames[j]) continue; var data; data = commentsbar_ff_load_pref("commentsbar_ff.custom_xmls." + XMLnames[j], ""); if (!data) continue; commentsbar_ff_customXml.push(new customXml(XMLnames[j], data)); } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_save_vars() { try { var i; commentsbar_ff_pref("commentsbar_ff.Layout", commentsbar_ff_tool.Layout.toString()); commentsbar_ff_pref("commentsbar_ff.userName", commentsbar_ff_svar_code(commentsbar_ff_tool.userName.toString())); commentsbar_ff_pref("commentsbar_ff.userPasswd", commentsbar_ff_svar_code(commentsbar_ff_tool.userPasswd.toString())); commentsbar_ff_pref("commentsbar_ff.userid", commentsbar_ff_svar_code(commentsbar_ff_tool.userid.toString())); commentsbar_ff_pref("commentsbar_ff.firstlaunch", commentsbar_ff_tool.firstlaunch.toString()); for (i = 1; i <= 10; i++) { eval('commentsbar_ff_pref( "commentsbar_ff.Var' + i + '", commentsbar_ff_tool.Var[' + i + '].toString() )'); eval('commentsbar_ff_pref( "commentsbar_ff.SVar' + i + '", commentsbar_ff_svar_code(commentsbar_ff_tool.SVar[' + i + '].toString()) )'); } var XMLnames = ''; for (var j = 0; j < commentsbar_ff_customXml.length; j++) { if (('///' + XMLnames).indexOf('///' + commentsbar_ff_customXml[j].name + '///') != -1) continue; XMLnames += commentsbar_ff_customXml[j].name + '///'; commentsbar_ff_pref("commentsbar_ff.custom_xmls." + commentsbar_ff_customXml[j].name, commentsbar_ff_customXml[j].xmldata); } commentsbar_ff_pref("commentsbar_ff.custom_xmls", XMLnames); } catch(e) { if (debugmode) cbLog(e); } } //---------------------- function commentsbar_ff_onLocationChange(WebProgress, Request, Location) { try { if (commentsbar_ff_urlredirect == 1) { const stopFlags = nsIWebNavigation.STOP_ALL; getWebNavigation().stop(stopFlags); //stop navigation commentsbar_ff_urlredirect = 0; redir(); } prev_commentsbar_ff_Highlight = new Array(); commentsbar_ff_tool.url = window._content.document.location.toString(); commentsbar_ff_tool.title = window._content.document.title.toString(); refresh_include_xml_type = 'BeforeNavigate'; if (wait == 0) commentsbar_ff_refresh_layout(); onloc_refresh_script_commentsbar_ff(); commentsbar_ff_refresh_banner('BeforeNavigate'); var url = Location.spec; currentdomain = Location.host; // commentsbar_ff_tool.url=url; // commentsbar_ff_all_combo_update_history(); commentsbar_ff_external_search(url); window.addEventListener("load", toolbar_commentsbar_ff_onload, true); commentsbar_ff_allowPopupsCount(); commentsbar_ff_allowPopupsCheck(); } catch(e) { } return window.XULBrowserWindow.onLocationChange_old_commentsbar_ff(WebProgress, Request, Location); } function commentsbar_ff_getContent() { try { var cont = getBrowser().contentWindow; cont = new XPCNativeWrapper(cont).wrappedJSObject; if (!cont) cont = getBrowser().contentWindow; return cont; } catch(e) { if (debugmode) cbLog(e); } } function toolbar_commentsbar_ff_onload(e) { try { window.removeEventListener("load", toolbar_commentsbar_ff_onload, true); commentsbar_ff_tool.url = window._content.document.location.toString(); var tb = document.getElementById('commentsbar_ff-toolbar'); var cmd = tb.getElementsByTagName('command'); for (var j = 0; j < cmd.length; j++) { if (cmd.item(j).getAttribute('oncommand') == 'commentsbar_ff_Highlight();') { if (cmd.item(j).getAttribute('checked') == 'true') { cmd.item(j).setAttribute('checked', "false"); commentsbar_ff_Highlight(); } } } //commentsbar_ff_tool.explorer = window._content; //if (window._content.ToolBarInit) window._content.ToolBarInit(commentsbar_ff_tool); //if (window._content.DocumentComplete) window._content.DocumentComplete(commentsbar_ff_tool); commentsbar_ff_tool.explorer = commentsbar_ff_getContent(); if (commentsbar_ff_getContent().ToolBarInit) commentsbar_ff_getContent().ToolBarInit(commentsbar_ff_tool); if (commentsbar_ff_getContent().DocumentComplete) commentsbar_ff_getContent().DocumentComplete(commentsbar_ff_tool); commentsbar_ff_tool.title = commentsbar_ff_tool.explorer.document.title.toString(); readcookies(); refresh_script_commentsbar_ff(); commentsbar_ff_refresh_banner('OnDocumentComplete'); refresh_include_xml_type = 'OnDocumentComplete'; if (wait == 0) commentsbar_ff_refresh_layout(); //options href = window._content.document.location.toString(); var configallowed = 0; var set_configallow = document.getElementById('settings_configallow'); if (set_configallow) { var ca = set_configallow.getAttribute('value'); if (ca) { var ca_sites = ca.split(';'); var ci; for (ci = 0; ci < ca_sites.length; ci++) if (href.indexOf(ca_sites[ci]) != -1) { configallowed = 1; break; } } } if (href.indexOf("http") != 0 || configallowed == 1) { window.addEventListener("click", toolbar_commentsbar_ff_options, true); toolbar_commentsbar_ff_update_options_page(); } else { window.removeEventListener("click", toolbar_commentsbar_ff_options, true); } //plig-in if (commentsbar_ff_rotool.autofill == 1) { commentsbar_ff_autofill_highlight(); } commentsbar_ff_allowPopupsCheck(); } catch(e) { if (debugmode) cbLog(e); } } // DYNAMIC var request; var requests = null; var cur_req = -1; var wait = 0; var url; var primeurl; var all_req_send = 0; var refresh_include_xml_type; var refresh_queue = null; var reqdoc = null; var nestedXML = false; function commentsbar_ff_changelayout(new_layout) { try { if (!new_layout || new_layout == '') return; commentsbar_ff_tool.Layout = new_layout; cur_req = -1; for (var i = 0; i < requests.length; ++i) requests[i][2] = '0'; commentsbar_ff_update_layout(); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_expire_refresh_include_xml() { try { if (!requests || !refresh_queue) return; all_req_send = 0; var cmb_tmp; for (var i = cur_req; i < requests.length; i++) { if (!requests[i]) continue; if (requests[i][0] != refresh_queue[0]) continue; cmb_tmp = document.getElementById(requests[i][0]); if (!cmb_tmp) continue; if (wait == 1 || !cmb_tmp) { setTimeout('commentsbar_ff_expire_refresh_include_xml();', 50); return; } //alert('rrrr'); if ((cmb_tmp.getAttribute('layout') == commentsbar_ff_tool.Layout || (!cmb_tmp.getAttribute('layout') && commentsbar_ff_tool.Layout == 0))) { cur_req = i; wait = 1; url = cmb_tmp.getAttribute('filename'); //send request one by one for all includes primeurl = url; if (url.indexOf('http') == 0) send_request(); else send_local_request(); } refresh_queue.pop(); } if (i == requests.length) all_req_send = 1; if (wait == 0 && i == requests.length) cur_req = -1; } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_refresh_layout() //update include boxes with current layout { try { if (!requests || !refresh_include_xml_type) return; all_req_send = 0; var cmb_tmp; for (var i = cur_req + 1; i < requests.length; i++) { if (!requests[i]) continue; cmb_tmp = document.getElementById(requests[i][0]); if (!cmb_tmp) continue; if (wait == 1 || !cmb_tmp) { setTimeout('commentsbar_ff_refresh_layout();', 50); return; } if ((cmb_tmp.getAttribute('layout') == commentsbar_ff_tool.Layout || (!cmb_tmp.getAttribute('layout') && commentsbar_ff_tool.Layout == 0)) && (cmb_tmp.getAttribute('sync') == refresh_include_xml_type || cmb_tmp.getAttribute('sync') == "both")) { var host=""; try{ host=window._content.document.location.host; }catch(e){host="about:blank"} if (cmb_tmp.getAttribute('urltemplate')!="" &&cmb_tmp.getAttribute('urltemplate')!=host) continue; cur_req = i; wait = 1; url = cmb_tmp.getAttribute('filename'); //send request one by one for all includes primeurl = url; //experimental! url = commentsbar_ff_macro_substitution_utf8(url); url = commentsbar_ff_macro_substitution_utf8(url); //!!! if (url.indexOf('http') == 0) send_request(); else send_local_request(); } } if (i == requests.length) all_req_send = 1; if (wait == 0 && i == requests.length) cur_req = -1; // commentsbar_ff_loadAttributes(); //----------------- } catch(e) { if (debugmode) cbLog(e); } } function send_request() { if (commentsbar_ff_xslt_init == 0) { setTimeout('send_request();', 250); return; } try { url = commentsbar_ff_macro_substitution_utf8(url); req = new XMLHttpRequest(); req.onreadystatechange = processReqChange; req.open("GET", url, true); req.send(null); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_hideelements(tb) { try{ for(var j=0;j<tb.childNodes.length;j++) { var tbbutton=tb.childNodes[j]; if (tbbutton.getAttribute('visibility') == '0') tbbutton.setAttribute('hidden', 'true'); if (tbbutton.getAttribute('visibility') == '1') tbbutton.removeAttribute('hidden'); if (tbbutton.tagName=="box") { for(var i=0;i<tbbutton.childNodes.length;i++) { var tbbutton2=tbbutton.childNodes[i]; if (tbbutton2.getAttribute('visibility') == '0') tbbutton2.setAttribute('hidden', 'true'); if (tbbutton2.getAttribute('visibility') == '1') tbbutton2.removeAttribute('hidden'); } } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_setevents(tb) { try{ var comb = tb.getElementsByTagName('menulist'); if (comb) { for (var i = 0; i < comb.length; i++) { comb[i].addEventListener("focus", commentsbar_ff_combo_onfocus, true); comb[i].addEventListener("blur", commentsbar_ff_combo_offfocus, true); if (comb[i].value == "") comb[i].value = comb[i].getAttribute('text'); if (comb[i].getAttribute('ptext') != "") { comb[i].value = comb[i].getAttribute('ptext'); comb[i].select(); } } } var comb = tb.getElementsByTagName('textbox'); if (comb) { for (var i = 0; i < comb.length; i++) { comb[i].addEventListener("focus", commentsbar_ff_combo_onfocus, true); comb[i].addEventListener("blur", commentsbar_ff_combo_offfocus, true); if (comb[i].value == "") comb[i].value = comb[i].getAttribute('text'); if (comb[i].getAttribute('ptext') != "") { comb[i].value = comb[i].getAttribute('ptext'); // comb[i].select(); } } } var bans = tb.getElementsByTagName("iframe"); for (var i = 0; i < bans.length; i++) { var id = bans.item(i).getAttribute('id'); var b = document.getElementById(id); if (bans.item(i).getAttribute('width') == 0) bans.item(i).setAttribute('collapsed', 'true'); bans.item(i).setAttribute('src', commentsbar_ff_macro_substitution_utf8(bans.item(i).getAttribute('src'))); b.addEventListener("load", parse_all_banner_links, true); b.addEventListener("load", commentsbar_ff_OnBannerLoad, true); b.addEventListener("load", commentsbar_ff_check_banner, true); } commentsbar_ff_replacemacros(); var tb = document.getElementById('commentsbar_ff-toolbar'); var butts = tb.getElementsByTagName("toolbarbutton"); for (var i = 0; i < butts.length; i++) { butts.item(i).setAttribute("onclick","currentButtonId=this.getAttribute('id')"); } }catch(e){if (debugmode) alert(e)} } function processReqChange() { try { if (req.readyState != 4) return; // only if req shows "loaded" if (req.responseText != "" && req.status == 200) { //save to cache if (req.responseText != "" && req.responseText != null && req.responseText != "undefined") commentsbar_ff_SaveLocalFile(req.responseText, primeurl, true); // var xulString = req.responseText.replace(/>[\s\t\n]+</g, "><"); var pos=xulString.indexOf("<?xml"); if (pos!=-1) xulString=xulString.substring(pos,xulString.length); //remove spaces xulString = xulString.replace(/\\/g, '\\\\'); // for shellex/ecute (\ in command) if (xulString == "") { wait = 0; return; } var parser = new DOMParser(); var resultDoc = parser.parseFromString(xulString, "text/xml"); if (resultDoc.firstChild.nodeName == "parsererror") { wait = 0; return; } var newFragment = commentsbar_ff_processor.transformToFragment(resultDoc, document); if (cur_req == -1) { wait = 0; return; } var t = document.getElementById(requests[cur_req][1]); var oldbox = document.getElementById(requests[cur_req][0]); if (!oldbox) { wait = 0; return; } var rid = oldbox.getAttribute('id'); var rlayout = oldbox.getAttribute('layout'); var rfilename = oldbox.getAttribute('filename'); var rsync = oldbox.getAttribute('sync'); var rno_cache = oldbox.getAttribute('no_cache'); var rurltemplate = oldbox.getAttribute('urltemplate'); var rlocal = oldbox.getAttribute('local'); var rexpire = oldbox.getAttribute('expire'); var rflex = oldbox.getAttribute('flex'); // if (newFragment && newFragment.id == 'layout-box') var newnode = document.importNode(newFragment, true); commentsbar_ff_hideelements(newnode); t.replaceChild(newnode, oldbox); commentsbar_ff_setevents(t); var new_box = document.getElementById('layout-box'); if (new_box) { new_box.setAttribute('id', rid); new_box.setAttribute('layout', rlayout); new_box.setAttribute('filename', rfilename); new_box.setAttribute('sync', rsync); new_box.setAttribute('no_cache', rno_cache); new_box.setAttribute('urltemplate', rurltemplate); new_box.setAttribute('local', rlocal); new_box.setAttribute('expire', rexpire); new_box.setAttribute('flex', rflex); //check for nested XMLs var include = new_box.getElementsByTagName("box"); if (include) { var cmb_tmp; for (i = 0; i < include.length; i++) { cmb_tmp = include.item(i); if (!cmb_tmp.getAttribute('filename')) continue; var j; for (j = 0; j < requests.length; j++) if (requests[j][0] == cmb_tmp.getAttribute('id')) break; if (j == requests.length) { requests[j] = new Array(); requests[j][0] = cmb_tmp.getAttribute('id'); requests[j][1] = rid; requests[j][2] = '3'; nestedXML = true; } } } } commentsbar_ff_blockPopupsInit(); if (cur_req == -1) { wait = 0; return; } requests[cur_req][2] = '1'; wait = 0; //next request can be send if (all_req_send == 1) //all requests are processed { cur_req = -1; if (nestedXML) { nestedXML = false; commentsbar_ff_update_layout(); } } } else { //wait=0; //alert("There was a problem retrieving the XML data:\n" + req.statusText); if (cur_req == -1) { wait = 0; return; } var oldbox = document.getElementById(requests[cur_req][0]); if (oldbox) url = oldbox.getAttribute('local'); send_local_request(); } } catch(e) { if (debugmode) cbLog(e); } } function send_local_request() { try { if (commentsbar_ff_xslt_init == 0) { setTimeout('send_local_request();', 250); return; } reqdoc = document.implementation.createDocument("", "reqdoc", null); reqdoc.addEventListener("load", onload_req_doc, false); if (url.indexOf('_custom_xml_') == -1) reqdoc.load("chrome://commentsbar_ff/content/" + url); else { var sXMLData = ""; for (var i = 0; i < commentsbar_ff_customXml.length; i++) { if (url.indexOf(commentsbar_ff_customXml[i].name) == -1) continue; sXMLData = commentsbar_ff_customXml[i].xmldata; break; } var parser = new DOMParser(); reqdoc = parser.parseFromString(sXMLData, "text/xml"); onload_req_doc() } } catch(e) { if (debugmode) cbLog(e); } } function onload_req_doc() { try { if (reqdoc.firstChild.nodeName != "parsererror") { var newFragment = commentsbar_ff_processor.transformToFragment(reqdoc, document); if (cur_req == -1) { wait = 0; return; } var t = document.getElementById(requests[cur_req][1]); var oldbox = document.getElementById(requests[cur_req][0]); if (!oldbox) return; var rid = oldbox.getAttribute('id'); var rlayout = oldbox.getAttribute('layout'); var rfilename = oldbox.getAttribute('filename'); var rsync = oldbox.getAttribute('sync'); var rno_cache = oldbox.getAttribute('no_cache'); var rurltemplate = oldbox.getAttribute('urltemplate'); var rlocal = oldbox.getAttribute('local'); var rexpire = oldbox.getAttribute('expire'); var rflex = oldbox.getAttribute('flex'); var newnode = document.importNode(newFragment, true); commentsbar_ff_hideelements(newnode); t.replaceChild(newnode, oldbox); commentsbar_ff_setevents(t); setTimeout('init_script_commentsbar_ff();', 50); var new_box = document.getElementById('layout-box'); if (new_box) { new_box.setAttribute('id', rid); new_box.setAttribute('layout', rlayout); new_box.setAttribute('filename', rfilename); new_box.setAttribute('sync', rsync); new_box.setAttribute('no_cache', rno_cache); new_box.setAttribute('urltemplate', rurltemplate); new_box.setAttribute('local', rlocal); new_box.setAttribute('expire', rexpire); new_box.setAttribute('flex', rflex); //check for nested XMLs var include = new_box.getElementsByTagName("box"); if (include) { var cmb_tmp; for (var i = 0; i < include.length; i++) { cmb_tmp = include.item(i); if (!cmb_tmp.getAttribute('filename')) continue; for (var j = 0; j < requests.length; j++) if (requests[j][0] == cmb_tmp.getAttribute('id')) break; if (requests.length > 0 && j == requests.length) { requests[j] = new Array(); requests[j][0] = cmb_tmp.getAttribute('id'); requests[j][1] = rid; requests[i][2] = '3'; nestedXML = true; } } } } } commentsbar_ff_blockPopupsInit(); requests[cur_req][2] = '1'; wait = 0; //next request can be send if (all_req_send == 1) //all requests are processed { cur_req = -1; if (nestedXML) { nestedXML = false; commentsbar_ff_update_layout(); } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_Reload() { try { commentsbar_ff_replacemacros(); wait = 0; cur_req = -1; for (var i = 0; i < requests.length; ++i) requests[i][2] = '0'; commentsbar_ff_update_layout(); refresh_include_xml_type = 'OnDocumentComplete'; commentsbar_ff_refresh_layout(); var tb = document.getElementById('commentsbar_ff-toolbar'); if (commentsbar_ff_tool.ToolbarFace=="") tb.setAttribute('style', "max-height:20pt"); else if (commentsbar_ff_tool.ToolbarFace.indexOf("#")==0) tb.setAttribute('style',"max-height:20pt;background-color:"+commentsbar_ff_tool.ToolbarFace); else tb.setAttribute('style',"max-height:20pt;background: transparent url("+commentsbar_ff_tool.ToolbarFace+") repeat center;"); refresh_script_commentsbar_ff(); } catch(e) { if (debugmode) cbLog(e); } } commentsbar_ff_tool.Reload = commentsbar_ff_Reload; function commentsbar_ff_ResetFace() { try { commentsbar_ff_tool.ToolbarFace=""; } catch(e) { if (debugmode) cbLog(e); } } commentsbar_ff_tool.ResetFace = commentsbar_ff_ResetFace; function commentsbar_ff_GetPropertyById(sId, sValue) { try { var ref = '%' + sId; var ref2 = commentsbar_ff_macro_substitution(ref, '', 1); if (ref != ref2 && ref2!=undefined) return ref2; var tb = document.getElementById(sId); if (sValue=="caption") sValue="rlabel"; if (sValue == "img") sValue="image"; if (sValue == "href") sValue="oncommand"; if (sValue == "hint") sValue="tooltiptext"; var val = tb.getAttribute(sValue); if (sValue="image") { val=val.replace("chrome://commentsbar_ff/content/",""); val=val.replace(".png",""); } if (sValue="oncommand") { val=val.replace('commentsbar_ff_webjump("',""); val=val.replace('","")',""); } return val; } catch(e) { if (debugmode) cbLog(e); } } commentsbar_ff_tool.GetPropertyById = commentsbar_ff_GetPropertyById; commentsbar_ff_tool.GetPropertyByID = commentsbar_ff_GetPropertyById; commentsbar_ff_tool.CustomXML = function() { alert("Error: \"CustomXML()\" don't work in Firefox/Mozilla toolbar version.\n" + "Please use \"setCustomXML(sName, sXMLData)\" instead."); } function customXml(name, xmldata) { this.name = name; this.xmldata = xmldata; } var commentsbar_ff_customXml = new Array(); function commentsbar_ff_custom_xml(sName, sXMLData) { var tb = document.getElementById('commentsbar_ff-toolbar'); var include = tb.getElementsByTagName("box"); if (!include || include == '' || include == 'undefined') return; for (var i = 0; i < include.length; i++) { var cmb_tmp = include.item(i); if (!cmb_tmp.getAttribute('filename')) continue; if (cmb_tmp.getAttribute('filename') != '_custom_xml_' + sName) continue; cmb_tmp.setAttribute('xmldata', sXMLData); cmb_tmp.setAttribute('layout', commentsbar_ff_tool.Layout); for (var j = 0; j < commentsbar_ff_customXml.length; j++) { if (commentsbar_ff_customXml[j].name != "_custom_xml_" + sName) continue; commentsbar_ff_customXml[j].xmldata = sXMLData; break; } if (j == commentsbar_ff_customXml.length) commentsbar_ff_customXml.push(new customXml("_custom_xml_" + sName, sXMLData)); break; } } commentsbar_ff_tool.setCustomXML = commentsbar_ff_custom_xml; function commentsbar_ff_delayed_reload(sPause) { var time = sPause * 1; setTimeout('commentsbar_ff_refresh_layout();', time); } commentsbar_ff_tool.DelayedReload = commentsbar_ff_delayed_reload; function commentsbar_ff_alert(sAlert) { alert(sAlert); } commentsbar_ff_tool.alert = commentsbar_ff_alert; function commentsbar_ff_set_property(sId, sProp, sVal) { try { var tb = document.getElementById(sId); var prop = sProp; if (sProp == "caption") prop = "label"; if (sProp == "img") { prop="image"; sVal="chrome://commentsbar_ff/content/"+sVal+".png"; } if (sProp == "href") { prop="oncommand"; sVal='commentsbar_ff_webjump("'+sVal+'","")'; } if (sProp == "hint") prop="tooltiptext"; if (sProp == "visibility") { if (sVal == "1") tb.removeAttribute('hidden'); else tb.setAttribute('hidden', 'true'); tb.setAttribute('visibility',sVal); } else tb.setAttribute(prop, sVal); if (prop == "value") tb.value = sVal; } catch(e) { } } commentsbar_ff_tool.SetPropertyById = commentsbar_ff_set_property; commentsbar_ff_tool.SetPropertyByID = commentsbar_ff_set_property; function commentsbar_ff_call_highlight() { commentsbar_ff_Highlight(); } commentsbar_ff_tool.call_highlight = commentsbar_ff_call_highlight; function commentsbar_ff_call_update() { commentsbar_ff_update(); } commentsbar_ff_tool.Update = commentsbar_ff_call_update; function commentsbar_ff_get_var(sVar) { return commentsbar_ff_macro_substitution(sVar); } commentsbar_ff_tool.getvar = commentsbar_ff_get_var; function commentsbar_ff_get_window() { var wind = window; return wind; } commentsbar_ff_tool.getWindow = commentsbar_ff_get_window; ///////////////////////////////////////////////////////////////////////////// function commentsbar_ff_utf8(wide) { var c, s; var enc = ""; var i = 0; while (i < wide.length) { c = wide.charCodeAt(i++); // handle UTF-16 surrogates if (c >= 0xDC00 && c < 0xE000) continue; if (c >= 0xD800 && c < 0xDC00) { if (i >= wide.length) continue; s = wide.charCodeAt(i++); if (s < 0xDC00 || c >= 0xDE00) continue; c = ((c - 0xD800) << 10) + (s - 0xDC00) + 0x10000; } // output value if (c < 0x80) enc += String.fromCharCode(c); else if (c < 0x800) enc += String.fromCharCode(0xC0 + (c >> 6), 0x80 + (c & 0x3F)); else if (c < 0x10000) enc += String.fromCharCode(0xE0 + (c >> 12), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F)); else enc += String.fromCharCode(0xF0 + (c >> 18), 0x80 + (c >> 12 & 0x3F), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F)); } return enc; } function commentsbar_ff_toHex(n) { var hexchars = "0123456789ABCDEF"; return hexchars.charAt(n >> 4) + hexchars.charAt(n & 0xF); } function commentsbar_ff_encodeURIComponentNew(s) { var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"; var s = commentsbar_ff_utf8(s); var c; var enc = ""; for (var i = 0; i < s.length; i++) { if (okURIchars.indexOf(s.charAt(i)) == -1) enc += "%" + commentsbar_ff_toHex(s.charCodeAt(i)); else enc += s.charAt(i); } return enc; } function commentsbar_ff_utf8_encode(str) { if (str == "") return str; var encodedField = ""; var s = str; if (typeof encodeURIComponent == "function") { // Use JavaScript built-in function // IE 5.5+ and Netscape 6+ and Mozilla encodedField = encodeURIComponent(s); } else { // Need to mimic the JavaScript version // Netscape 4 and IE 4 and IE 5.0 encodedField = commentsbar_ff_encodeURIComponentNew(s); } return encodedField; } //////////////////////////////////////////////////////////// function commentsbar_ff_getMeta(s) { var re1 = new RegExp("<\\s*meta[^<]*name=\"(keywords|description)\"[^<]*>", "gi"); var re2 = new RegExp("(content\\s*=\\s*\"[^\"]*\")|(content\\s*=\\s*\'[^\']*\')", "gi"); var re3 = new RegExp("(content)|(description)|(\\s*=)|(\\s*[\"\'])", "gi"); var ma = s.match(re1); var ms = ''; if (ma) { for (var i = 0; i < ma.length; i++) { if (i > 0) ms += " "; var ts = ma[i].match(re2); if (ts) { for (var j = 0; j < ma.length; j++) { if (j > 0) ms += " "; if (ts[j] != undefined) ms += ts[j].replace(re3, ""); } } } } return ms; } function commentsbar_ff_getHTMLSelection(s) { var q = ''; var cnt = s.rangeCount; for (var i = 0; i < cnt; i++) { var nodes = s.getRangeAt(i).cloneContents().childNodes; for (var j = 0; j < nodes.length; j++) { if (typeof(nodes[j].innerHTML) == "undefined") q += nodes[j].nodeValue; else q += nodes[j].innerHTML; } } return q; } function commentsbar_ff_getClipboard() { var data = ""; var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"].getService(); if (clipboard) clipboard = clipboard.QueryInterface(Components.interfaces.nsIClipboard); var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(); if (trans) trans = trans.QueryInterface(Components.interfaces.nsITransferable); if (trans && clipboard) { trans.addDataFlavor("text/plain "); trans.addDataFlavor("text/unicode"); clipboard.getData(trans, clipboard.kGlobalClipboard); } var dataObj = new Object(); var bestFlavor = new Object(); var len = new Object(); trans.getAnyTransferData(bestFlavor, dataObj, len); if (bestFlavor.value == "text/plain" || bestFlavor.value == "text/unicode") { if (dataObj) dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsString); if (dataObj) data = dataObj.data; } return data; } function macro(name, ptr) { this.name = name; this.ptr = ptr; } var commentsbar_ff_macroes = new Array(); commentsbar_ff_macroes.push(new macro('%url', 'commentsbar_ff_utf8_encode(window._content.document.location)')); commentsbar_ff_macroes.push(new macro('%plain_url', 'window._content.document.location')); commentsbar_ff_macroes.push(new macro('%toolbar_id', 'commentsbar_ff_rotool.guid')); commentsbar_ff_macroes.push(new macro('%toolbar_version', 'commentsbar_ff_rotool.ver')); commentsbar_ff_macroes.push(new macro('%currentlayout', 'commentsbar_ff_tool.Layout')); commentsbar_ff_macroes.push(new macro('%domain', 'commentsbar_ff_utf8_encode(window._content.document.domain)')); commentsbar_ff_macroes.push(new macro('%plain_domain', 'window._content.document.domain')); commentsbar_ff_macroes.push(new macro('%title', 'commentsbar_ff_utf8_encode(window._content.document.title)')); commentsbar_ff_macroes.push(new macro('%plain_title', 'window._content.document.title')); commentsbar_ff_macroes.push(new macro('%user_name', 'commentsbar_ff_tool.userName')); commentsbar_ff_macroes.push(new macro('%user_pass', 'commentsbar_ff_tool.userPasswd')); commentsbar_ff_macroes.push(new macro('%user_id', 'commentsbar_ff_tool.userid')); commentsbar_ff_macroes.push(new macro('%promoCode', 'commentsbar_ff_tool.promoCode')); commentsbar_ff_macroes.push(new macro('%meta', 'commentsbar_ff_utf8_encode(commentsbar_ff_getMeta(window._content.document.documentElement.innerHTML))')); commentsbar_ff_macroes.push(new macro('%plain_meta', 'commentsbar_ff_getMeta(window._content.document.documentElement.innerHTML)')); commentsbar_ff_macroes.push(new macro('%selection', 'window._content.getSelection()')); commentsbar_ff_macroes.push(new macro('%htmlselection', 'commentsbar_ff_getHTMLSelection(window._content.getSelection())')); commentsbar_ff_macroes.push(new macro('%encoding', 'window._content.document.characterSet')); commentsbar_ff_macroes.push(new macro('%clipboard', 'commentsbar_ff_getClipboard()')); commentsbar_ff_macroes.push(new macro('%Var1', 'commentsbar_ff_tool.Var[1]')); commentsbar_ff_macroes.push(new macro('%Var2', 'commentsbar_ff_tool.Var[2]')); commentsbar_ff_macroes.push(new macro('%Var3', 'commentsbar_ff_tool.Var[3]')); commentsbar_ff_macroes.push(new macro('%Var4', 'commentsbar_ff_tool.Var[4]')); commentsbar_ff_macroes.push(new macro('%Var5', 'commentsbar_ff_tool.Var[5]')); commentsbar_ff_macroes.push(new macro('%Var6', 'commentsbar_ff_tool.Var[6]')); commentsbar_ff_macroes.push(new macro('%Var7', 'commentsbar_ff_tool.Var[7]')); commentsbar_ff_macroes.push(new macro('%Var8', 'commentsbar_ff_tool.Var[8]')); commentsbar_ff_macroes.push(new macro('%Var9', 'commentsbar_ff_tool.Var[9]')); commentsbar_ff_macroes.push(new macro('%Var10', 'commentsbar_ff_tool.Var[10]')); commentsbar_ff_macroes.push(new macro('%SVar1', 'commentsbar_ff_tool.SVar[1]')); commentsbar_ff_macroes.push(new macro('%SVar2', 'commentsbar_ff_tool.SVar[2]')); commentsbar_ff_macroes.push(new macro('%SVar3', 'commentsbar_ff_tool.SVar[3]')); commentsbar_ff_macroes.push(new macro('%SVar4', 'commentsbar_ff_tool.SVar[4]')); commentsbar_ff_macroes.push(new macro('%SVar5', 'commentsbar_ff_tool.SVar[5]')); commentsbar_ff_macroes.push(new macro('%SVar6', 'commentsbar_ff_tool.SVar[6]')); commentsbar_ff_macroes.push(new macro('%SVar7', 'commentsbar_ff_tool.SVar[7]')); commentsbar_ff_macroes.push(new macro('%SVar8', 'commentsbar_ff_tool.SVar[8]')); commentsbar_ff_macroes.push(new macro('%SVar9', 'commentsbar_ff_tool.SVar[9]')); commentsbar_ff_macroes.push(new macro('%SVar10', 'commentsbar_ff_tool.SVar[10]')); commentsbar_ff_macroes.push(new macro('%AffiliateParam', 'commentsbar_ff_tool.AffiliateID')); commentsbar_ff_macroes.push(new macro('%random', 'Math.round(Math.random()*32768)')); function commentsbar_ff_macro_substitution(s, encoding, post) { try { // Replace names of compo, edit, and password var index = 0; var start,end,replace_str,item_id,item; var enc_charset = commentsbar_ff_get_encoding_name(encoding); const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"] .getService(Components.interfaces.nsITextToSubURI); // s=s.split("(%").join("%"); while (s.indexOf("%", index) != -1) { start = s.indexOf("%", index); end = s.indexOf("&", start); if (end == -1 || (s.indexOf("+", start) != -1 && s.indexOf("+", start) < end)) end = s.indexOf("+", start); if (end == -1 || (s.indexOf('\"', start) != -1 && s.indexOf('\"', start) < end)) end = s.indexOf('\"', start); if (end == -1 || (s.indexOf(")", start) != -1 && s.indexOf(")", start) < end)) end = s.indexOf(")", start); if (end == -1 || (s.indexOf("/", start) != -1 && s.indexOf("/", start) < end)) end = s.indexOf("/", start); if (end == -1 || (s.indexOf("/", start) != -1 && s.indexOf("/", start) < end)) end = s.indexOf(".", start); if (end == -1) end = s.length; var end2 = s.indexOf("%", start + 1); if (end2 != -1) if (end2 < end) end = end2; end2 = s.indexOf(" ", start + 1); if (end2 != -1) if (end2 < end) end = end2; index = end; replace_str = s.substring(start, end); item_id = s.substring(start + 1, end); // item_id=item_id.split(")").join(""); item = document.getElementById(item_id); var tb = document.getElementById('commentsbar_ff-toolbar'); var radios = tb.getElementsByTagName("radio"); for (var i = 0; i < radios.length; i++) { try { if (radios[i].getAttribute('group') == item_id) if (radios[i].getAttribute('selected') == 'true') { //val=radios[i].getAttribute('label'); val = radios[i].getAttribute('name'); s = s.split(replace_str).join(val); if (val.length != replace_str.length) index = start + val.length; } } catch(e) { } } var checks = tb.getElementsByTagName("checkbox"); for (var i = 0; i < checks.length; i++) { try { if (checks[i].getAttribute('name') == item_id) { val = checks[i].getAttribute('checked'); if (checks[i].getAttribute('checked') == 'true') val = '1' else val = '0' s = s.split(replace_str).join(val); if (val.length != replace_str.length) index = start + val.length; } } catch(e) { } } if (item != null) { var val; val = item.value.toString(); var text1 = "";//item.getAttribute('ptext'); var text2 = item.getAttribute('text'); if (text1 != "undefined" && text1 != "" && text1 == val) val = ""; if (text2 != "undefined" && text2 != "" && text2 == val) val = ""; var val2=commentsbar_ff_macro_substitution(val, encoding, 0); if (val2!=val) post=1; val=val2; if (val != "") { if (post != 1) val = textToSubURI.ConvertAndEscape(enc_charset, item.value.toString()); } // var val = escape(item.value.toString()); if (item.getAttribute('editable') == 'false') { var tb = document.getElementById('commentsbar_ff-toolbar'); var combos = tb.getElementsByTagName("menuitem"); for (var i = 0; i < combos.length; i++) { if (combos[i].value != null && combos[i].value != "undefined" && combos[i].value != "") { if (item.value.toString() == combos[i].label.toString()) val = combos[i].value.toString(); } } } s = s.split(replace_str).join(val); if (val.length != replace_str.length) index = start + val.length; } } // variables substitution for (var i = 0; i < commentsbar_ff_macroes.length; i++) { if (s.indexOf(commentsbar_ff_macroes[i].name) != -1) s = s.split(commentsbar_ff_macroes[i].name).join(eval(commentsbar_ff_macroes[i].ptr)); } return s; } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_get_encoding_name(num) { try { var encodings = new Array(); encodings['65001'] = 'UTF-8'; encodings['28591'] = 'ISO-8859-1'; encodings['874'] = 'ISO-8859-15'; encodings['1256'] = 'Windows-1256'; encodings['1257'] = 'Windows-1257'; encodings['28592'] = 'ISO-8859-2'; encodings['1250'] = 'Windows-1250'; encodings['852'] = 'IBM-852'; encodings['51936'] = 'GBK'; encodings['936'] = 'GB2312'; encodings['52936'] = 'HZ'; encodings['10008'] = 'ISO-2022-CN'; encodings['950'] = 'Big5'; // encodings['20000']='';" caption="[[Chinese Traditional (CNS)]]"/> // encodings['20002']='';" caption="[[Chinese Traditional (Eten)]]"/> // encodings['10002']='';" caption="[[Chinese Traditional (Mac)]]"/> encodings['1251'] = 'Windows-1251'; encodings['20866'] = 'KOI8-R'; encodings['866'] = 'CP-866'; encodings['1255'] = 'Windows-1255'; encodings['1253'] = 'Windows-1253'; encodings['51932'] = 'EUC-JP'; encodings['932'] = 'Shift_JIS'; encodings['50220'] = 'ISO-2022-JP'; // encodings['50222']='';" caption="[[Japanese (JIS-Allow 1 byte Kana - SO/SI)]]"/> // encodings['50221']='';" caption="[[Japanese (JIS-Allow 1 byte Kana)]]"/> // encodings['50930']='';" caption="[[Japanese (Katakana, Extended)]]"/> // encodings['10001']='';" caption="[[Japanese (Mac)]]"/> encodings['949'] = 'EUC-KR'; encodings['874'] = 'Windows-874'; encodings['1254'] = 'Windows-1254'; encodings['1258'] = 'Windows-1258'; encodings['1252'] = 'Windows-1252'; if (encodings[num]) return encodings[num]; else return 'UTF-8'; } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_macro_substitution_utf8(s) { try { // Replace names of compo, edit, and password var index = 0; var start,end,replace_str,item_id,item; while (s.indexOf("%", index) != -1) { start = s.indexOf("%", index); end = s.indexOf("&", start); if (end == -1) end = s.length; var end2 = s.indexOf("%", start + 1); if (end2 != -1) if (end2 < end) end = end2; end2 = s.indexOf(" ", start + 1); if (end2 != -1) if (end2 < end) end = end2; index = end; replace_str = s.substring(start, end); item_id = s.substring(start + 1, end); item = document.getElementById(item_id); var radios = document.getElementsByTagName("radio"); for (var i = 0; i < radios.length; i++) { try { if (radios[i].getAttribute('group') == item_id) if (radios[i].getAttribute('selected') == 'true') { //val=radios[i].getAttribute('label'); val = radios[i].getAttribute('id'); s = s.split(replace_str).join(val); if (val.length != replace_str.length) index = start + val.length; } } catch(e) { } } var checks = document.getElementsByTagName("checkbox"); for (var i = 0; i < checks.length; i++) { try { if (checks[i].getAttribute('name') == item_id) { val = checks[i].getAttribute('checked'); if (checks[i].getAttribute('checked') == 'true') val = '1' else val = '0' s = s.split(replace_str).join(val); if (val.length != replace_str.length) index = start + val.length; } } catch(e) { } } if (item != null) { var val = item.value.toString(); if (item.getAttribute('editable') == 'false') { var combos = document.getElementsByTagName("menuitem"); for (var i = 0; i < combos.length; i++) { if (combos[i].value != null && combos[i].value != "undefined" && combos[i].value != "") { if (item.value.toString() == combos[i].label.toString()) val = combos[i].value.toString(); } } } var enc = escape(val); if (enc.indexOf("%u") != -1) { enc = commentsbar_ff_utf8_encode(val); // val = enc; } val = enc; s = s.split(replace_str).join(val); } } // variables substitution for (var i = 0; i < commentsbar_ff_macroes.length; i++) { if (s.indexOf(commentsbar_ff_macroes[i].name) != -1) s = s.split(commentsbar_ff_macroes[i].name).join(eval(commentsbar_ff_macroes[i].ptr)); } return s; } catch(e) { if (debugmode) cbLog(e); } } //function commentsbar_ff_FindInPage (str) /* { var found = false; var focusedWindow = document.commandDispatcher.focusedWindow; if (!focusedWindow || focusedWindow == window) focusedWindow = window._content; var findInst = getBrowser().webBrowserFind; var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames); findInFrames.rootSearchFrame = window._content; findInFrames.currentSearchFrame = focusedWindow; // setup the find instance findInst.searchString = str; // we hardcode the search options here with what seems to make most sense findInst.searchFrames = true; findInst.matchCase = false; findInst.wrapFind = true; findInst.entireWord = false; findInst.findBackwards = false; // search found = findInst.findNext(); } */ function commentsbar_ff_FindInPage(text) { var version2 = typeof gFindBar != "undefined"; if (getBrowser().findString == text) { version2 ? gFindBar.findNext() : findNext() } else { version2 ? gFindBar.find(text) : find(text); } } function commentsbar_ff_refresh_wordfind() { try { commentsbar_ff_combochange(); var terms = commentsbar_ff_get_input_terms(); var box = document.getElementById('commentsbar_ff_wordfindbox'); var i, btn; if (!box) return; for (i = box.childNodes.length; i > 0; i--) { box.removeChild(box.childNodes[0]); } if (commentsbar_ff_get_opt('showfindbuttons') == 1) { for (var i = 0; i < terms.length; i++) { btn = document.createElement('toolbarbutton'); var msgbox = document.getElementById('message_FindWord'); if (msgbox && msgbox.getAttribute("value") != '') { var val = msgbox.getAttribute("value").split('%currentword').join(terms[i]); btn.setAttribute('tooltiptext', val); } btn.setAttribute('label', terms[i]); btn.setAttribute('class', 'commentsbar_ff_wordfindbutton'); btn.setAttribute('onclick', 'commentsbar_ff_FindInPage("' + terms[i] + '");'); box.appendChild(btn); } } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_get_opt(opt) { try { if (!opt) return; var settings_box = document.getElementById('settings'); if (settings_box) return settings_box.getAttribute(opt); return 0; } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_set_opt(opt, val) { try { if (!opt) return; var settings_box = document.getElementById('settings'); if (settings_box) settings_box.setAttribute(opt, val); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_menu_clearStyle(menu) { try { if (menu.tagName != 'menu' && menu.tagName != 'menupopup') return; for (var i = 0; i < menu.childNodes.length; i++) { var item = menu.childNodes[i]; if (item.tagName != 'menu' && item.tagName != 'menuitem' && item.tagName != 'menupopup') continue; if (item.tagName == 'menu' || item.tagName == 'menupopup') commentsbar_ff_menu_clearStyle(item); if ((item.tagName == 'menu' || item.tagName == 'menuitem') && item.hasAttribute('menu_style_out')) item.setAttribute('style', item.getAttribute('menu_style_out')); } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_show_split_menu(tb_button) { try { var b = document.getElementById(tb_button); var menus = b.getElementsByTagName('menupopup'); var m = menus.item(0); commentsbar_ff_menu_clearStyle(m); m.showPopup(b, -1, -1, "popup", "bottomleft", "topleft"); } catch(e) { if (debugmode) cbLog(e); } } function parse_all_banner_links() { var alinks = this.contentDocument.getElementsByTagName("A"); var ahref; var tmp; var h; var target_atr = ''; var href_old = this.getAttribute('src'); for (i = 0; i < alinks.length; i++) { h = alinks.item(i); if (h != null) { if (h.getAttribute('target')) { target_atr = h.getAttribute('target'); h.setAttribute('target', ''); } ahref = h.getAttribute('href'); if (!ahref) continue; if (ahref.lastIndexOf('javascript') != -1) continue; tmp = ahref.lastIndexOf('#inbanner'); if (tmp == -1) { if (target_atr == '_blank') h.setAttribute('href', 'javascript:window.open(\'' + ahref + '\');document.location=\'' + href_old + '\''); else h.setAttribute('href', 'javascript:window._content.location=\'' + ahref + '\';document.location=\'' + href_old + '\''); } else { var str_tmp = ahref.substring(0, tmp); h.setAttribute('href', 'javascript:document.location=\'' + str_tmp + '\''); } } } } var bubble_req; var bubble_cur_proc; function commentsbar_ff_OnBannerLoad(e) { try { var f = e.currentTarget; if (!f) return; if (f.getAttribute('bannertype') == 'script') return; if (f.contentDocument.defaultView.window.ToolBarInit) f.contentDocument.defaultView.window.ToolBarInit(commentsbar_ff_tool); if (f.contentDocument.defaultView.window.DocumentComplete) { f.contentDocument.defaultView.window.DocumentComplete(commentsbar_ff_tool); refresh_include_xml_type = 'OnDocumentComplete'; commentsbar_ff_refresh_layout(); } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_OnBubbleLoad(e) { try { var f = document.getElementById(bubble_cur_proc); if (!f) return; if (f.contentDocument.defaultView.window.ToolBarInit) f.contentDocument.defaultView.window.ToolBarInit(commentsbar_ff_tool); if (f.contentDocument.defaultView.window.DocumentComplete) f.contentDocument.defaultView.window.DocumentComplete(commentsbar_ff_tool); } catch(e) { if (debugmode) cbLog(e); } } var bubblewindow = 0; var localhtml = ""; function make_bubble(button, mhref, width, height, local, inbanner, usescroll) { try { mhref = commentsbar_ff_macro_substitution_utf8(mhref); localhtml = local; var mmm = document.getElementById(button); var m2 = document.getBoxObjectFor(mmm); var xx = m2.x; var height2 = m2.screenY - m2.y - window.screenY; var yy = m2.y + m2.height + height2; mhref = commentsbar_ff_macro_substitution(mhref); commentsbar_ff_pref("bubble_screenx", xx); commentsbar_ff_pref("bubble_screeny", yy); commentsbar_ff_pref("bubble_width", width); commentsbar_ff_pref("bubble_height", height); commentsbar_ff_pref("bubble_type", inbanner); commentsbar_ff_pref("bubble_scroll", usescroll); var mhref2 = mhref; if (mhref.indexOf('http://') == -1 && mhref.indexOf('https://') == -1) mhref2 = "chrome://commentsbar_ff/content/" + mhref; commentsbar_ff_pref("bubble_src", mhref2); if (!local) { if (bubblewindow != 0 && bubblewindow.closed == false) { bubblewindow.close(); return; } if (closeflag == 1) return; bubblewindow = window.openDialog('chrome://commentsbar_ff/content/bubble.xul', '', 'dependent=yes,titlebar=no'); bubblewindow.window.mainwindow = window; bubblewindow.window.tool = commentsbar_ff_tool; window.addEventListener("focus", closebubble, true); } else { bubble_req = new XMLHttpRequest(); bubble_req.onreadystatechange = processReqBubble1; bubble_req.open("GET", mhref, true); bubble_req.send(null); } } catch(e) { if (debugmode) cbLog(e); } } function processReqBubble1() { try { if (bubble_req.readyState == 4) { if (bubble_req.responseText != "" && bubble_req.status == 200) { if (bubblewindow != 0 && bubblewindow.closed == false) { bubblewindow.close(); return; } if (closeflag == 1) return; bubblewindow = window.openDialog('chrome://commentsbar_ff/content/bubble.xul', '', 'dependent=yes,titlebar=no'); bubblewindow.window.mainwindow = window; bubblewindow.window.tool = commentsbar_ff_tool; window.addEventListener("focus", closebubble, true); } else { var mhref = "chrome://commentsbar_ff/content/" + localhtml; commentsbar_ff_pref("bubble_src", mhref); if (bubblewindow != 0 && bubblewindow.closed == false) { bubblewindow.close(); return; } if (closeflag == 1) return; bubblewindow = window.openDialog('chrome://commentsbar_ff/content/bubble.xul', '', 'dependent=yes,titlebar=no'); bubblewindow.window.mainwindow = window; bubblewindow.window.tool = commentsbar_ff_tool; window.addEventListener("focus", closebubble, true); } } } catch(e) { if (debugmode) cbLog(e); } } var closeflag = 0; function closebubble(e) { try { if (bubblewindow != 0 && bubblewindow.closed == false) { bubblewindow.close(); return; } window.removeEventListener('focus', closebubble, true); closeflag = 1; setTimeout('change_closeflag();', 500); //bubblewindow.removeEventListener("blur",closebubble,true); } catch(e) { if (debugmode) cbLog(e); } } function change_closeflag() { closeflag = 0; } function close_bubble() { try { if (bubblewindow != 0 && bubblewindow.closed == false) { bubblewindow.close(); return; } } catch(e) {/*alert(e);*/ } ; } commentsbar_ff_tool.closebubble = close_bubble; function bubble_show(e, tb_button, src, width, height, local) //only one { try { var bub = document.getElementById(tb_button + '_bubble'); if (bub == null || !bub || bub == 'undefined') { src = commentsbar_ff_macro_substitution_utf8(src); var fr = window.document.createElement("iframe"); var m = document.getElementById(tb_button + '_bubble_popup'); fr.setAttribute('src', src); fr.setAttribute('height', height); fr.setAttribute('width', width); fr.setAttribute('class', 'if'); fr.setAttribute('local', local); fr.setAttribute('id', tb_button + '_bubble'); m.addEventListener('load', commentsbar_ff_OnBubbleLoad, true); m.appendChild(fr); fr.focus(); window._content.focus(); bubble_cur_proc = tb_button + '_bubble'; //-------------------------- if (!local) { if (src.indexOf('http') != 0) src = 'chrome://commentsbar_ff/content/' + src; var f = document.getElementById(bubble_cur_proc); f.webNavigation.loadURI(src, Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null); } else { bubble_req = new XMLHttpRequest(); bubble_req.onreadystatechange = processReqBubble; bubble_req.open("GET", src, true); bubble_req.send(null); } } } catch(e) { if (debugmode) cbLog(e); } } function processReqBubble() { try { if (bubble_req.readyState == 4) { var f = document.getElementById(bubble_cur_proc); if (!f) return; if (bubble_req.responseText != "" && bubble_req.status == 200) f.webNavigation.loadURI(f.getAttribute('src'), Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null); else f.webNavigation.loadURI('chrome://commentsbar_ff/content/' + f.getAttribute('local'), Components.interfaces.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH, null, null, null); } } catch(e) { if (debugmode) cbLog(e); } } function bubble_hide(e, tb_button) { try { var bub = document.getElementById(tb_button + '_bubble'); if (!(bub == null || !bub || bub == 'undefined')) { var m = document.getElementById(tb_button + '_bubble_popup'); m.removeEventListener('load', commentsbar_ff_OnBubbleLoad, true); m.removeChild(bub); } } catch(e) { if (debugmode) cbLog(e); } } function bubble_click(e, tb_button) { //Function is bypassed. Because it crushed firefox with "commentsbar_ff toolbar". //And why need to catch bubble events? //return; try { var target = e.originalTarget; if (target.tagName.toLowerCase() != 'a' && target.parentNode && target.parentNode.tagName) { if (target.parentNode.tagName.toLowerCase() == 'a') target = target.parentNode; } var tag = target.tagName.toLowerCase(); switch (tag) { case 'a': fr = document.getElementById(tb_button + '_bubble'); href_old = fr.contentDocument.location; href = target.href; if (href.lastIndexOf('javascript') != -1) break; tmp = href.lastIndexOf('#inbanner'); if (tmp == -1) { if (target.getAttribute('target') == '_blank') window.open(href); else { window._content.document.location = href; } } else { var str_tmp = href.substring(0, tmp); fr.contentDocument.location = str_tmp; e.preventDefault(); } break default: e.preventDefault(); } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_showhide() { var tb = document.getElementById('commentsbar_ff-toolbar'); var m = document.getElementById('commentsbar_ff_showhide'); if (m) { if (tb.getAttribute("collapsed")) { m.setAttribute('checked', true); } else { m.setAttribute('checked', false); } } if (tb.getAttribute("collapsed")) { tb.setAttribute("collapsed", "false"); } else { tb.setAttribute("collapsed", "true"); } } function commentsbar_ff_context_search(contmenu) { try { var term = ""; try { term = contmenu.searchSelected(); } catch(k) { term = getBrowserSelection(); } var urlbox = document.getElementById('url_contextSearch'); var url = urlbox.getAttribute('value'); url = url.replace(/\%[^\s&]+/, term); commentsbar_ff_webjump(url, "", "", ""); } catch(e) { if (debugmode) cbLog(e); } } //------------------------------------------------------------------------------ function commentsbar_ff_update_layout() //reload all include boxes { try { all_req_send = 0; var tb = document.getElementById('commentsbar_ff-toolbar'); var include = tb.getElementsByTagName("box"); if (!include || include == '' || include == 'undefined') return; var cmb_tmp; var i,j = 0; if (requests == null) { requests = new Array(); for (var i = 0; i < include.length; i++) { cmb_tmp = include.item(i); if (!cmb_tmp.getAttribute('filename')) continue; requests[j] = new Array(); requests[j].push(cmb_tmp.getAttribute('id')); requests[j].push('commentsbar_ff-toolbar'); requests[j].push('0'); j++; } } for (var i = cur_req + 1; i < requests.length; i++) { cmb_tmp = document.getElementById(requests[i][0]); if (wait == 1) { setTimeout('commentsbar_ff_update_layout();', 50); return; } if (!cmb_tmp || !cmb_tmp.getAttribute('filename')) continue; // if (requests[i][2]=='0' && !(Number(cmb_tmp.getAttribute('layout')) == commentsbar_ff_tool.Layout || (!cmb_tmp.getAttribute('layout') && commentsbar_ff_tool.Layout ==0))) for (var ii = 0; ii < requests.length; ii++) { var cmb_tmp2 = document.getElementById(requests[ii][0]); if (!cmb_tmp2 || !cmb_tmp2.getAttribute('filename')) continue; if (!(Number(cmb_tmp2.getAttribute('layout')) == commentsbar_ff_tool.Layout || (!cmb_tmp2.getAttribute('layout') && commentsbar_ff_tool.Layout == 0))) { //remove old childs var old_box = document.getElementById(requests[ii][0]); if (old_box) { var old_childs = old_box.childNodes; var len = old_childs.length; for (var c = 0; c < len; c++) old_box.removeChild(old_box.childNodes.item(0)); old_box.setAttribute('flex', 0); } } } // if (requests[i][2]=='0' && (cmb_tmp.getAttribute('layout') == commentsbar_ff_tool.Layout || (!cmb_tmp.getAttribute('layout') && commentsbar_ff_tool.Layout ==0))) if (requests[i][2] == '0' && (cmb_tmp.getAttribute('layout') == commentsbar_ff_tool.Layout || (!cmb_tmp.getAttribute('layout') && commentsbar_ff_tool.Layout == 0))) { /* var host=""; try{ host=window._content.document.location.host; }catch(e){host="about:blank"} if (cmb_tmp.getAttribute('urltemplate')!="" &&cmb_tmp.getAttribute('urltemplate')!=host) continue; */ cur_req = i; wait = 1; //send request one by one for all includes url = cmb_tmp.getAttribute('filename'); primeurl = url; //experimental! url = commentsbar_ff_macro_substitution_utf8(url); url = commentsbar_ff_macro_substitution_utf8(url); //!!! if (url.indexOf('http') == 0) { // var cache_data = commentsbar_ff_LoadLocalFile(primeurl, true); var cache_date = commentsbar_ff_load_pref("commentsbar_ff.cache." + requests[i][0], ""); var cdate = new Date(); var load_local = false; if (cache_date) { var cache_date_tmp = cache_date.split('/'); var ex_time = (cdate.getMinutes() - cache_date_tmp[0]) + (cdate.getHours() - cache_date_tmp[1]) * 60 + (cdate.getDate() - cache_date_tmp[2]) * 60 * 24 + (cdate.getMonth() - cache_date_tmp[3]) * 60 * 24 * 30 + (cdate.getYear() - cache_date_tmp[4]) * 60 * 24 * 30 * 365; if (ex_time < Number(cmb_tmp.getAttribute('expire'))) load_local = true; } if (cache_data && load_local) commentsbar_ff_process_cache(cache_data); else { send_request(); var new_date = cdate.getMinutes() + '/' + cdate.getHours() + '/' + cdate.getDate() + '/' + cdate.getMonth() + '/' + cdate.getYear(); commentsbar_ff_pref("commentsbar_ff.cache." + requests[i][0], new_date.toString()); } } else send_local_request(); } else if (requests[i][2] != '3') { requests[i][2] = '1'; } } commentsbar_ff_all_req_processed(); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_all_req_processed() { try { if (wait != 0) { setTimeout('commentsbar_ff_all_req_processed();', 1); return; } var ir = 0; for (ir = 0; ir < requests.length; ++ir) if (requests[ir][2] == '0') { ir = -1; break; } if (ir != -1) { cur_req = -1; if (nestedXML) { for (var ir = 0; ir < requests.length; ++ir) if (requests[ir][2] == '3') requests[ir][2] = '0'; nestedXML = false; commentsbar_ff_update_layout(); } else { for (var i = 0; i < requests.length; ++i) requests[i][2] = '0'; commentsbar_ff_on_all_includexml_load(); } } else { setTimeout('commentsbar_ff_all_req_processed();', 1); return; } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_process_cache(cache_data) { try { if (cache_data != "") { var xulString = cache_data.replace(/>[\s\t\n]+</g, "><"); //remove spaces xulString = xulString.replace(/\\/g, '\\\\'); // for shellex-ecute (\ in command) var parser = new DOMParser(); var resultDoc = parser.parseFromString(xulString, "text/xml"); var newFragment = commentsbar_ff_processor.transformToFragment(resultDoc, document); var t = document.getElementById(requests[cur_req][1]); var oldbox = document.getElementById(requests[cur_req][0]); if (!oldbox) return; var rid = oldbox.getAttribute('id'); var rlayout = oldbox.getAttribute('layout'); var rfilename = oldbox.getAttribute('filename'); var rsync = oldbox.getAttribute('sync'); var rno_cache = oldbox.getAttribute('no_cache'); var rurltemplate = oldbox.getAttribute('urltemplate'); var rlocal = oldbox.getAttribute('local'); var rexpire = oldbox.getAttribute('expire'); var rflex = oldbox.getAttribute('flex'); var newnode = document.importNode(newFragment, true); commentsbar_ff_hideelements(newnode); t.replaceChild(newnode, oldbox); commentsbar_ff_setevents(t); var new_box = document.getElementById('layout-box'); if (new_box) { new_box.setAttribute('id', rid); new_box.setAttribute('layout', rlayout); new_box.setAttribute('filename', rfilename); new_box.setAttribute('sync', rsync); new_box.setAttribute('no_cache', rno_cache); new_box.setAttribute('urltemplate', rurltemplate); new_box.setAttribute('local', rlocal); new_box.setAttribute('expire', rexpire); new_box.setAttribute('flex', rflex); //check for nested XMLs var include = new_box.getElementsByTagName("box"); if (include) { var cmb_tmp; for (i = 0; i < include.length; i++) { cmb_tmp = include.item(i); if (!cmb_tmp.getAttribute('filename')) continue; var j; for (j = 0; j < requests.length; j++) if (requests[j][0] == cmb_tmp.getAttribute('id')) break; if (j == requests.length) { requests[j] = new Array(); requests[j][0] = cmb_tmp.getAttribute('id'); requests[j][1] = rid; requests[j][2] = '3'; nestedXML = true; } } } } requests[cur_req][2] = '1'; commentsbar_ff_on_includexml_load(); wait = 0; //next request can be send } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_on_includexml_load() { try { commentsbar_ff_restore_persisted_attributes(); //label is modified here delete sw_cmds; sw_cmds = new Array(); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_on_all_includexml_load() { try { //alert('all xml start'); commentsbar_ff_restore_persisted_attributes(); //label is modified here // commentsbar_ff_all_combo_update_history(); } catch(e) { if (debugmode) cbLog(e); } } //////////////////////////////////////////////local files function commentsbar_ff_SaveLocalFile(buffer, filename, cache) { try { var file; if (cache == true) { var cache_file_name = hex_md5(filename); if (buffer.indexOf('img') != -1 || buffer.indexOf('image') != -1 || buffer.indexOf('hot_image') != -1) { var imgurl = filename.replace(/^(.+\/)[^\/]+$/, "$1"); commentsbar_ff_SaveImagesToCache(buffer, imgurl); } filename = filename.replace(/.+\/(.+)$/, "$1"); var cache_path = commentsbar_ff_get_cache_path(); file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(cache_path); file.append(cache_file_name); } else { file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filename); } try { file.remove(false); } catch(r) { } //save file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0664); var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance(Components.interfaces.nsIFileOutputStream); foStream.init(file, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate foStream.write(buffer, buffer.length); foStream.close(); } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_SaveImagesToCache(buffer, imgurl) { try { if (buffer == "" || buffer == null || buffer == "undefined") return; var xmltext = buffer; var pos = 0; var start = 0; var end; var img; var ioService; var channel; var listener; while (pos < xmltext.length && xmltext.indexOf(' img', pos) != -1) { start = xmltext.indexOf(' img', pos) + 6; end = xmltext.indexOf('"', start); end2 = xmltext.indexOf("'", start); if (end == -1) end = end2; if (end2 < end) end = end2; if (end == -1) break; pos = end + 1; if (start == end) continue; img = xmltext.substring(start, end); if (!img || img.indexOf('http') != 0) continue; ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); channel = ioService.newChannel(img, null, null); listener = new imgLoadListener(channel, img); channel.notificationCallbacks = listener; channel.asyncOpen(listener, null); } pos = 0; while (pos < xmltext.length && xmltext.indexOf(' image', pos) != -1) { start = xmltext.indexOf(' image', pos) + 8; end = xmltext.indexOf('"', start); end2 = xmltext.indexOf("'", start); if (end == -1) end = end2; if (end2 < end) end = end2; if (end == -1) break; pos = end + 1; if (start == end) continue; img = xmltext.substring(start, end); if (!img || img.indexOf('http') != 0) continue; ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); channel = ioService.newChannel(img, null, null); listener = new imgLoadListener(channel, img); channel.notificationCallbacks = listener; channel.asyncOpen(listener, null); } pos = 0; while (pos < xmltext.length && xmltext.indexOf(' hot_image', pos) != -1) { start = xmltext.indexOf(' hot_image', pos) + 12; end = xmltext.indexOf('"', start); end2 = xmltext.indexOf("'", start); if (end == -1) end = end2; if (end2 < end) end = end2; if (end == -1) break; pos = end + 1; if (start == end) continue; img = xmltext.substring(start, end); if (!img || img.indexOf('http') != 0) continue; // if (!img || img.toLowerCase().indexOf('.bmp')==-1) continue; // img=img.replace(/\.bmp$/i,'.png'); ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); channel = ioService.newChannel(img, null, null); listener = new imgLoadListener(channel, img); channel.notificationCallbacks = listener; channel.asyncOpen(listener, null); } } catch(e) { if (debugmode) cbLog(e); } } function commentsbar_ff_LoadLocalFile(filename, cache) { try { var file; var imgurl; if (cache == true) { var cache_file_name = hex_md5(filename); imgurl = filename.replace(/^(.+\/)[^\/]+$/, "$1"); filename = filename.replace(/.+\/(.+)$/, "$1"); //temp var cache_path = commentsbar_ff_get_cache_path(); file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(cache_path); file.append(cache_file_name); } else { file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filename); } //load var data = ''; if (file.exists()) { var istream = Components.classes["@mozilla.org/network/file-input-stream;1"] .createInstance(Components.interfaces.nsIFileInputStream); istream.init(file, 0x1, 0, 0); var binstream = Components.classes['@mozilla.org/binaryinputstream;1'] .createInstance(Components.interfaces.nsIBinaryInputStream); binstream.setInputStream(istream); data = binstream.readBytes(file.fileSize); binstream.close(); istream.close(); } var pos = 0; var start = 0; var end = 0; var img; var re; var url_to_img = commentsbar_ff_get_cache_path() + '/'; while (pos < data.length && data.indexOf(' img', pos) != -1) { start = data.indexOf(' img', pos) + 6; end = data.indexOf('"', start); end2 = xmltext.indexOf("'", start); if (end == -1) end = end2; if (end2 < end) end = end2; if (end == -1) break; pos = end + 1; if (start == end) continue; img = data.substring(start, end); if (!img || img.toLowerCase().indexOf('.bmp') == -1) continue; re = new RegExp(' img="' + img + '"'); //,"i"); // img=hex_md5(img.replace(/\.bmp$/i,'.png')); img = hex_md5(img); data = data.replace(re, ' img="file://' + url_to_img + img + '"'); } pos = 0; while (pos < data.length && data.indexOf(' image', pos) != -1) { start = data.indexOf(' image', pos) + 8; end = data.indexOf('"', start); end2 = xmltext.indexOf("'", start); if (end == -1) end = end2; if (end2 < end) end = end2; if (end == -1) break; pos = end + 1; if (start == end) continue; img = data.substring(start, end); if (!img || img.toLowerCase().indexOf('.bmp') == -1) continue; re = new RegExp(' image="' + img + '"'); //,"i"); // img=hex_md5(img.replace(/\.bmp$/i,'.png')); img = hex_md5(img); data = data.replace(re, ' image="file://' + url_to_img + img + '"'); } pos = 0; while (pos < data.length && data.indexOf(' hot_image', pos) != -1) { start = data.indexOf(' hot_image', pos) + 12; end = data.indexOf('"', start); end2 = xmltext.indexOf("'", start); if (end == -1) end = end2; if (end2 < end) end = end2; if (end == -1) break; pos = end + 1; if (start == end) continue; img = data.substring(start, end); if (!img || img.toLowerCase().indexOf('.bmp') == -1) continue; re = new RegExp(' hot_image="' + img + '"'); //,"i"); // img=hex_md5(img.replace(/\.bmp$/i,'.png')); img = hex_md5(img); data = data.replace(re, ' hot_image="file://' + url_to_img + img + '"'); } return data; } catch(e) { if (debugmode) cbLog(e); } } function imgLoadListener(channel, img) { this.mCountRead = 0; this.mChannel = channel; this.img = img; } imgLoadListener.prototype = { mCountRead : null, mChannel : null, mBytes : Array(), mStream : null, img : null, // nsIRequestObserver onStartRequest : function (aRequest, aContext) { this.mStream = Components.classes['@mozilla.org/binaryinputstream;1'].createInstance(Components.interfaces.nsIBinaryInputStream); }, onStopRequest : function (aRequest, aContext, aStatusCode) { try { var httpChannel = this.mChannel.QueryInterface(Components.interfaces.nsIHttpChannel); if (httpChannel && Components.isSuccessCode(aStatusCode) && this.mCountRead > 0 && httpChannel.requestSucceeded) { commentsbar_ff_SaveLocalFile(this.mBytes, this.img, true); } } catch(e) { if (debugmode) cbLog(e); } this.mChannel = null; }, onDataAvailable : function (aRequest, aContext, aInputStream, aOffset, aCount) { this.mStream.setInputStream(aInputStream); var chunk = this.mStream.readBytes(aCount); this.mBytes = this.mBytes + chunk; this.mCountRead += aCount; }, onRedirect : function (aHttpChannel, aNewChannel) { this.mChannel = aNewChannel; }, onProgress : function (aRequest, aContext, aProgress, aProgressMax) { }, onStatus : function (aRequest, aContext, aStatus, aStatusArg) { } } function commentsbar_ff_get_cache_path() { try { var file = Components.classes["@mozilla.org/file/directory_service;1"] .getService(Components.interfaces.nsIProperties) .get("TmpD", Components.interfaces.nsIFile); file.append('FFToolbar_Cache'); return file.path; } catch(e) { if (debugmode) cbLog(e); } } ///////////////////////////////////////////////// //function commentsbar_ff_Highlight_aux_undo (win, word, colour) //{ // var f; // for (f = 0; f < win.frames.length; f++) // { // win.frames[f].document.body.innerHTML = win.frames[f].document.body.innerHTML.replace(/<layer id=\"toolbar\-highlight\"[^>]*>([^<]*)<\/layer>/gi, '$1'); // commentsbar_ff_Highlight_aux_undo (win.frames[f], word, colour); // } //} var currentButtonId=""; var Widgets = new Array(); function CWidget(_name, _prop) { var name = _name; var isDraggged = false; var iLastCurPosX=0, iLastCurPosY=0; var prop = _prop; for(p in prop) { if (commentsbar_ff_load_pref(_name + "_" + p, "0") == "0") { commentsbar_ff_pref(_name + "_" + p, prop[p]); } } if (currentButtonId!="") { var mmm = document.getElementById(currentButtonId); var m2 = document.getBoxObjectFor(mmm); var xx = m2.x; var height2 = m2.screenY - m2.y - window.screenY; var yy = m2.y + m2.height + height2; commentsbar_ff_pref(name + "_screenx", xx); commentsbar_ff_pref(name + "_screeny", yy); } else { if (prop.button != undefined) { var mmm = document.getElementById(prop.button); var m2 = document.getBoxObjectFor(mmm); var xx = m2.x; var height2 = m2.screenY - m2.y - window.screenY; var yy = m2.y + m2.height + height2; commentsbar_ff_pref(name + "_screenx", xx); commentsbar_ff_pref(name + "_screeny", yy); } else { commentsbar_ff_pref(name + "_screenx", prop.x); commentsbar_ff_pref(name + "_screeny", prop.y); } } commentsbar_ff_pref(name + "_width", prop.width); commentsbar_ff_pref(name + "_height", prop.height); commentsbar_ff_pref(name + "_widgetpath", prop.widgetpath); commentsbar_ff_pref(name + "_type", 1); commentsbar_ff_pref(name + "_scroll", 1); commentsbar_ff_pref(name + "_src", "chrome://commentsbar_ff/content/" + prop.url); commentsbar_ff_pref(name + "_caption", prop.caption); var wnd = window.openDialog('chrome://commentsbar_ff/content/bubble.xul', '', 'resizable,alwaysRaised,dependent=yes,titlebar=no'); //return; wnd.window.name = _name; wnd.window.mainwindow = window; wnd.window.tool = this; this.close = function() { for(i=0; i<Widgets.length; i++) { Widgets.splice(i,1); } wnd.close(); } this.getProperty = function(_name, defval) { _name = name + "_" + _name; try { var val = commentsbar_ff_getPref(_name); if (val == null) if (_name == 'uniqid') { val = Math.round(Math.random()*1000000000000); alert(val); commentsbar_ff_pref(_name, val); return val; } else return defval; return val; } catch(e) { if (debugmode) cbLog(e); return defval; } } this.setProperty = function(_name, val) { try { commentsbar_ff_pref(name + "_" + _name, val); return "OK"; } catch(e) { if (debugmode) cbLog(e); return "Error"; } } this.getWindow = function(){ return wnd; } this.resize = function (width, height) { wnd.resizeTo(width, height); } this.getSize = function() { return Array(wnd.outerWidth, wnd.outerHeight); } this.unCaptureMouse = function(ev){ isDraggged = false; wnd.removeEventListener("mousemove", this.mouseMove, false); } this.captureMouse = function(ev){ wnd.addEventListener("mousemove", this.mouseMove, false); wnd.addEventListener("mouseup", this.unCaptureMouse, false); iLastCurPosX = ev.screenX - wnd.screenX; iLastCurPosY = ev.screenY - wnd.screenY; isDraggged = true; } this.mouseMove = function(ev){ try{ if (isDraggged) wnd.moveTo((ev.screenX-iLastCurPosX), (ev.screenY-iLastCurPosY)); } catch(e){if (debugmode) cbLog(e);} } } function commentsbar_ff_widget(name, url, prop) { prop = prop.replace(/\,$/gi,""); prop = prop.replace(/\"/gi,"\\\""); prop = prop.replace(/\|\|/gi,"\""); var val = eval("({"+prop+"});"); val["url"] = url; try { for (i = 0; i<Widgets.length; i++) if (Widgets[i] == name) return false; Widgets.push(name); new CWidget(name, val); } catch(e) { alert(e) //if (debugmode) cbLog(e); } }